/* === Base Reset === */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: #f9f9f9;
  color: #222;
  line-height: 1.6;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* === Shared Brand === */
.brand,
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #01A200;
  color: #fff;
  font-size: 1.6rem;
  font-weight: 800;
  flex: 0 0 auto;
}

.brand-mark.small {
  width: 42px;
  height: 42px;
  font-size: 1.35rem;
}

/* === Auth Page === */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  background: linear-gradient(to right, #01A200, #047c00);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.14);
}

.auth-card .brand {
  margin-bottom: 2rem;
}

.brand h1 {
  font-size: 1.8rem;
  font-weight: 800;
  color: #01A200;
  line-height: 1.2;
}

.brand p {
  color: #555;
  font-size: 0.95rem;
}

/* === Tabs === */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  padding: 0.35rem;
  background: #f1f1f1;
  border-radius: 8px;
}

.tab {
  border: none;
  background: transparent;
  color: #333;
  padding: 0.65rem 1rem;
  border-radius: 5px;
  font-weight: 700;
  transition: all 0.2s ease;
}

.tab:hover {
  color: #01A200;
}

.tab.active {
  background: #01A200;
  color: #fff;
}

/* === Forms === */
.form {
  display: none;
}

.form.active {
  display: block;
}

.form h2 {
  font-size: 1.4rem;
  color: #222;
  margin-bottom: 1rem;
}

label {
  display: block;
  margin: 0.9rem 0 0.35rem;
  color: #333;
  font-size: 0.95rem;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  color: #222;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
.compose-editor:focus {
  border-color: #01A200;
  box-shadow: 0 0 0 3px rgba(1, 162, 0, 0.12);
}

button[type="submit"],
.compose-button {
  width: 100%;
  margin-top: 1.25rem;
  padding: 0.82rem 1rem;
  border: none;
  border-radius: 7px;
  background: #01A200;
  color: #fff;
  font-weight: 800;
  transition: opacity 0.2s ease, background 0.2s ease, transform 0.08s ease;
}

button[type="submit"]:hover,
.compose-button:hover {
  background: #047c00;
}

button[type="submit"]:active,
.compose-button:active {
  transform: translateY(1px);
}

button[disabled] {
  opacity: 0.7;
  cursor: not-allowed;
}

.message {
  min-height: 1.4rem;
  margin-top: 1rem;
  font-size: 0.95rem;
  font-weight: 700;
}

.message.success {
  color: #01A200;
}

.message.error {
  color: #b91c1c;
}

/* === App Layout === */
.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 260px 390px minmax(0, 1fr);
  background: #fff;
  overflow: hidden;
}

/* === Sidebar === */
.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid #ddd;
  background: #f9f9f9;
  padding: 1rem;
  overflow: hidden;
}

.sidebar-brand {
  padding-bottom: 1rem;
  border-bottom: 1px solid #ddd;
}

.sidebar-brand strong {
  display: block;
  color: #01A200;
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.25;
}

.sidebar-brand span {
  display: block;
  max-width: 165px;
  color: #555;
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compose-button {
  margin: 1.25rem 0 1rem;
}

.mailbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
  padding-right: 0.15rem;
}

.mailbox {
  width: 100%;
  padding: 0.72rem 0.78rem;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: #333;
  text-align: left;
  font-weight: 650;
  transition: background 0.18s ease, color 0.18s ease;
}

.mailbox:hover {
  background: #f1f1f1;
  color: #01A200;
}

.mailbox.active {
  background: #01A200;
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.sidebar-footer button,
.reader-actions button,
.modal-header button,
.back-button {
  padding: 0.6rem 0.75rem;
  border: 1px solid #01A200;
  border-radius: 7px;
  background: #fff;
  color: #01A200;
  font-weight: 800;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.sidebar-footer button:hover,
.reader-actions button:hover,
.modal-header button:hover,
.back-button:hover {
  background: #f4fff4;
}

/* === Mail List === */
.mail-list-panel {
  min-width: 0;
  border-right: 1px solid #ddd;
  background: #fff;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-header {
  padding: 1rem 1.1rem;
  border-bottom: 1px solid #ddd;
  background: #fff;
}

.panel-header h2 {
  color: #222;
  font-size: 1.45rem;
  line-height: 1.25;
  font-weight: 850;
  letter-spacing: -0.02em;
}

.panel-header p {
  color: #666;
  font-size: 0.92rem;
  margin-top: 0.2rem;
}

.message-list {
  overflow-y: auto;
  background: #fff;
}

.message-item {
  width: 100%;
  padding: 0.92rem 1.05rem;
  border: none;
  border-bottom: 1px solid #eee;
  background: #fff;
  text-align: left;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.message-item:hover {
  background: #f9f9f9;
}

.message-item.active {
  border-left: 4px solid #01A200;
  background: #f4fff4;
  padding-left: calc(1.05rem - 4px);
}

.message-item strong {
  display: block;
  color: #222;
  font-size: 0.98rem;
  line-height: 1.35;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-item span {
  display: block;
  color: #555;
  font-size: 0.88rem;
  line-height: 1.35;
  margin-top: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-item p {
  color: #777;
  font-size: 0.84rem;
  line-height: 1.35;
  margin-top: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === Reader === */
.reader-panel {
  min-width: 0;
  background: #fff;
  overflow-y: auto;
}

.empty-reader {
  height: 100%;
  display: grid;
  place-content: center;
  text-align: center;
  color: #555;
  padding: 2rem;
}

.empty-reader h2 {
  color: #222;
  font-size: 1.55rem;
  line-height: 1.25;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.empty-reader p {
  color: #666;
}

.message-reader {
  min-height: 100%;
}

.message-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.4rem;
  border-bottom: 1px solid #ddd;
  background: #fff;
}

.message-header h2 {
  color: #222;
  line-height: 1.25;
  font-size: 1.45rem;
  font-weight: 850;
  letter-spacing: -0.02em;
}

.message-header p {
  color: #666;
  font-size: 0.9rem;
  margin-top: 0.45rem;
  word-break: break-word;
}

.back-button {
  display: none;
  width: auto;
  margin-bottom: 0.75rem;
}

.reader-actions {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  flex: 0 0 auto;
}

.reader-body {
  padding: 1.4rem;
  color: #222;
}

.reader-body iframe {
  width: 100%;
  min-height: 65vh;
  border: none;
  background: #fff;
}

.reader-body pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
}

.attachment-list {
  padding: 0 1.4rem 1.4rem;
}

.attachment-link {
  display: inline-block;
  margin: 0.35rem 0.35rem 0 0;
  padding: 0.52rem 0.78rem;
  border: 1px solid #ddd;
  border-radius: 7px;
  color: #01A200;
  background: #fff;
  text-decoration: none;
  font-weight: 800;
}

.attachment-link:hover {
  background: #f4fff4;
}

/* === Compose Modal === */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.45);
  z-index: 2000;
}

.modal-card {
  width: 100%;
  max-width: 720px;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  background: #fff;
  border-radius: 12px;
  border: 1px solid #ddd;
  padding: 1.25rem;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.22);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.modal-header h2 {
  color: #01A200;
  font-size: 1.35rem;
}

.modal-header button {
  width: auto;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.35rem 0.65rem;
}

.compose-form label {
  margin-top: 0.75rem;
}

.compose-toolbar {
  display: flex;
  gap: 0.45rem;
  margin: 0.85rem 0 0.55rem;
}

.compose-toolbar button {
  width: auto;
  min-width: 2.2rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #f9f9f9;
  color: #222;
  font-weight: 800;
}

.compose-toolbar button:hover {
  background: #f1f1f1;
}

.compose-editor {
  width: 100%;
  min-height: 190px;
  padding: 0.75rem 0.85rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  outline: none;
  background: #fff;
  color: #222;
  line-height: 1.5;
  overflow-y: auto;
}

/* === Mobile === */
@media (max-width: 980px) {
  .app {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .reader-panel {
    display: none;
  }

  .reader-panel.open {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1000;
  }

  .back-button {
    display: inline-block;
  }
}

@media (max-width: 700px) {
  .app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar {
    height: auto;
    border-right: none;
    border-bottom: 1px solid #ddd;
  }

  .mail-list-panel {
    min-height: 70vh;
  }

  .auth-page {
    padding: 1rem;
  }

  .auth-card {
    padding: 1.5rem;
  }

  .message-header {
    flex-direction: column;
  }

  .reader-actions {
    width: 100%;
  }

  .reader-actions button {
    flex: 1;
  }

  .modal-card {
    max-height: calc(100vh - 1rem);
  }
}