:root {
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-50: #eff6ff;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --red-50: #fef2f2;
  --red-600: #dc2626;
  --white: #ffffff;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--gray-900);
  background: linear-gradient(180deg, var(--blue-50), var(--gray-50));
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--blue-600);
  color: var(--white);
}

.btn-primary:hover:not(:disabled) {
  background: var(--blue-700);
}

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--gray-200);
}

.btn-ghost {
  background: transparent;
  color: var(--gray-700);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--gray-100);
}

.btn-danger {
  background: var(--red-50);
  color: var(--red-600);
}

.error-banner {
  background: var(--red-50);
  color: var(--red-600);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}

.brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.brand-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 0.75rem;
  display: grid;
  place-items: center;
  background: var(--blue-50);
  color: var(--blue-600);
  border-radius: 16px;
  font-size: 1.5rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.75rem;
}

.subtitle {
  margin: 0.5rem 0 0;
  color: var(--gray-500);
}

.login-form label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--gray-700);
}

.login-form input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 1rem;
}

.login-form .btn-primary {
  width: 100%;
  padding: 0.75rem;
  margin-top: 0.25rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.brand-small {
  font-weight: 700;
  color: var(--blue-600);
}

.user-email {
  color: var(--gray-500);
  font-size: 0.9rem;
  margin-right: 0.25rem;
}

.mailbox-layout {
  display: grid;
  grid-template-columns: 220px 1fr 1.2fr;
  min-height: calc(100vh - 60px);
}

.sidebar {
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  padding: 1rem;
}

.sidebar h2,
.panel-header h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gray-500);
}

.folder-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.folder-list li {
  margin-bottom: 0.25rem;
}

.folder-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  color: var(--gray-700);
}

.folder-btn.active,
.folder-btn:hover {
  background: var(--blue-50);
  color: var(--blue-700);
}

.message-list-panel,
.message-detail-panel {
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  min-width: 0;
}

.message-detail-panel {
  border-right: none;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1rem 0.5rem;
  border-bottom: 1px solid var(--gray-100);
}

.pagination {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.85rem;
  color: var(--gray-500);
}

.message-list {
  overflow-y: auto;
  max-height: calc(100vh - 120px);
}

.message-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer;
}

.message-row:hover,
.message-row.active {
  background: var(--gray-50);
}

.message-row.unread .message-from,
.message-row.unread .message-subject {
  font-weight: 700;
}

.message-from {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-subject {
  grid-column: 1 / -1;
  color: var(--gray-700);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-date {
  font-size: 0.8rem;
  color: var(--gray-500);
}

.message-detail {
  padding: 1.25rem;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
}

.message-detail.empty {
  display: grid;
  place-items: center;
  color: var(--gray-500);
  min-height: 300px;
}

.message-meta {
  border-bottom: 1px solid var(--gray-200);
  padding-bottom: 1rem;
  margin-bottom: 1rem;
}

.message-meta h3 {
  margin: 0 0 0.75rem;
  font-size: 1.25rem;
}

.message-meta p {
  margin: 0.25rem 0;
  color: var(--gray-700);
  font-size: 0.92rem;
}

.message-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.message-body {
  line-height: 1.6;
  word-break: break-word;
}

.message-body pre {
  white-space: pre-wrap;
  font-family: inherit;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-content {
  position: relative;
  width: min(640px, calc(100vw - 2rem));
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-header h2 {
  margin: 0;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-500);
}

.compose-form label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.compose-form input,
.compose-form textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  margin-bottom: 0.85rem;
  font-size: 1rem;
  font-family: inherit;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.loading,
.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--gray-500);
}

@media (max-width: 960px) {
  .mailbox-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--gray-200);
  }

  .folder-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .folder-btn {
    width: auto;
  }

  .message-detail-panel {
    min-height: 320px;
  }
}
