/* ==========================================================================
   VARO — design tokens
   ========================================================================== */

:root {
  /* Color — light */
  --bg: #F6F7FA;
  --surface: #FFFFFF;
  --surface-alt: #EEF1F6;
  --surface-raised: #FFFFFF;
  --border: #E1E5EC;
  --border-strong: #C9CFDA;
  --text: #12151C;
  --text-muted: #5B6472;
  --text-faint: #8891A3;

  --primary: #2952E3;
  --primary-hover: #2245C9;
  --primary-contrast: #FFFFFF;
  --primary-tint: #EAEFFD;

  --success: #1F9D67;
  --success-tint: #E7F7EF;
  --danger: #D64545;
  --danger-tint: #FBEAEA;

  --focus-ring: #2952E3;

  /* Typography */
  --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* Layout */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;
  --sidebar-w: 340px;
  --header-h: 68px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(18, 21, 28, 0.06);
  --shadow-md: 0 8px 24px rgba(18, 21, 28, 0.08);
  --shadow-lg: 0 20px 48px rgba(18, 21, 28, 0.14);

  /* Motion */
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur-fast: 120ms;
  --dur-med: 220ms;
  --dur-slow: 420ms;
}

[data-theme="dark"] {
  --bg: #0D111A;
  --surface: #151B27;
  --surface-alt: #1B2231;
  --surface-raised: #1B2231;
  --border: #262F41;
  --border-strong: #354057;
  --text: #E9ECF4;
  --text-muted: #9AA3B5;
  --text-faint: #6C7689;

  --primary: #5B7CFF;
  --primary-hover: #7590FF;
  --primary-contrast: #0D111A;
  --primary-tint: #1B2444;

  --success: #34C685;
  --success-tint: #123324;
  --danger: #FF6B6B;
  --danger-tint: #391A1A;

  --focus-ring: #7590FF;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 56px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   Reset
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--dur-med) var(--ease), color var(--dur-med) var(--ease);
}
h1, h2, h3, p, dl, dd { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
ul { list-style: none; margin: 0; padding: 0; }
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px; top: -48px;
  background: var(--primary);
  color: var(--primary-contrast);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  z-index: 200;
  transition: top var(--dur-fast) var(--ease);
}
.skip-link:focus { top: 12px; }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ==========================================================================
   Views
   ========================================================================== */

.view { display: none; }
.view.is-active { display: block; }
.view-inbox.is-active { display: flex; flex-direction: column; height: 100dvh; }

/* ==========================================================================
   Buttons & fields
   ========================================================================== */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 46px;
  padding: 0 20px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn--primary { background: var(--primary); color: var(--primary-contrast); }
.btn--primary:hover { background: var(--primary-hover); }
.btn--block { width: 100%; }
.btn__spinner { display: none; }
.btn.is-loading .btn__label { visibility: hidden; }
.btn.is-loading .btn__spinner {
  display: block;
  position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
[data-theme="dark"] .btn.is-loading .btn__spinner { border-color: rgba(13,17,26,0.35); border-top-color: #0D111A; }
.btn:disabled { opacity: 0.7; cursor: default; }

@keyframes spin { to { transform: rotate(360deg); } }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.field input[type="text"],
.field input[type="password"],
.field input[type="search"] {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  width: 100%;
  transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.field input:focus {
  border-color: var(--primary);
  background: var(--surface);
}
.field input.is-invalid { border-color: var(--danger); }

.field__address {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-alt);
}
.field__address input {
  border: none;
  background: transparent;
  border-radius: 0;
}
.field__address input:focus { background: transparent; }
.field__address:focus-within { border-color: var(--primary); }
.field__domain {
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  background: var(--surface);
  border-left: 1px solid var(--border);
  white-space: nowrap;
}
.field__preview {
  font-size: 12.5px;
  color: var(--text-faint);
  margin-top: 2px;
}
.field__preview strong {
  font-family: var(--font-mono);
  color: var(--primary);
  font-weight: 500;
}

.field__hint-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.field__hint-text {
  font-size: 12.5px;
  color: var(--text-faint);
  margin-top: -2px;
}

/* ==========================================================================
   Icon buttons + inline icon system
   ========================================================================== */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-alt); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.is-active { color: var(--primary); background: var(--primary-tint); }

/* ==========================================================================
   Toasts
   ========================================================================== */

.toast-region {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 36px));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  animation: toast-in var(--dur-med) var(--ease);
}
.toast--error { border-left: 3px solid var(--danger); }
.toast--success { border-left: 3px solid var(--success); }
.toast--info { border-left: 3px solid var(--primary); }
.toast p { font-size: 13.5px; }
.toast.is-leaving { animation: toast-out var(--dur-fast) var(--ease) forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-6px); }
}

/* ==========================================================================
   AUTH VIEW
   ========================================================================== */

.view-auth {
  position: relative;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  overflow: hidden;
  background:
    radial-gradient(680px 420px at 15% -10%, var(--primary-tint), transparent 60%),
    var(--bg);
}
.view-auth.is-active { display: flex; }

.auth-scan {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 42px 42px;
  opacity: 0.35;
  mask-image: radial-gradient(680px 480px at 50% 20%, black, transparent 75%);
}

.auth-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px 34px;
  animation: card-rise var(--dur-slow) var(--ease);
}
@keyframes card-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; }
.auth-brand__name { font-family: var(--font-display); font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }

.auth-title {
  font-family: var(--font-display);
  font-size: 26px;
  line-height: 1.25;
  letter-spacing: -0.015em;
  font-weight: 600;
  margin-bottom: 10px;
}
.auth-subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }

.auth-form__note { font-size: 12.5px; color: var(--text-faint); text-align: center; margin-top: 16px; }

/* ==========================================================================
   APP HEADER
   ========================================================================== */

.app-header {
  height: var(--header-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
}
.app-header__left { display: flex; align-items: center; gap: 10px; }
.app-header__menu { display: none; }

.app-brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700; font-size: 15.5px; }

.app-header__address {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 auto 0 24px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px 6px 6px 14px;
}
.app-header__address-text {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-header__right { display: flex; align-items: center; gap: 6px; margin-left: auto; }

/* refresh scan-line, shown while auto/manual refresh is in flight */
.app-header.is-refreshing::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  animation: scan-sweep 1.1s linear infinite;
}
@keyframes scan-sweep {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

.icon-btn#btn-refresh.is-spinning svg { animation: spin 0.8s linear infinite; }

/* ==========================================================================
   APP BODY / LAYOUT
   ========================================================================== */

.app-body {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar__search { padding: 14px; border-bottom: 1px solid var(--border); }
.sidebar__search input {
  width: 100%;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 9px 14px;
  font-size: 13.5px;
}
.sidebar__search input:focus { border-color: var(--primary); }

.sidebar__list-wrap { flex: 1; overflow-y: auto; position: relative; }

.message-list { padding: 6px; }

.message-item {
  width: 100%;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  margin-bottom: 2px;
  transition: background-color var(--dur-fast) var(--ease);
  animation: item-in var(--dur-med) var(--ease) both;
}
@keyframes item-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.message-item:hover { background: var(--surface-alt); }
.message-item.is-selected { background: var(--primary-tint); border-color: var(--primary); }
.message-item__row { display: flex; align-items: center; gap: 8px; }
.message-item__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary);
  flex: 0 0 auto;
}
.message-item.is-read .message-item__dot { visibility: hidden; }
.message-item__subject {
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.message-item.is-read .message-item__subject { font-weight: 500; color: var(--text-muted); }
.message-item__time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  flex: 0 0 auto;
}

.skeleton-row, .skeleton-line, .skeleton-block {
  background: linear-gradient(90deg, var(--surface-alt) 25%, var(--border) 37%, var(--surface-alt) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}
.skeleton-row { height: 52px; margin: 8px 6px; }
.sidebar__skeleton { padding: 4px; }

.sidebar__empty, .sidebar__no-results {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
}
.sidebar__empty img { margin: 0 auto 16px; opacity: 0.9; }
.sidebar__empty-title { font-family: var(--font-display); font-weight: 600; font-size: 14.5px; color: var(--text); margin-bottom: 6px; }
.sidebar__empty-text { font-size: 12.5px; line-height: 1.5; }
.sidebar__no-results { font-size: 13px; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 20, 0.45);
  z-index: 15;
  animation: fade-in var(--dur-fast) var(--ease);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ==========================================================================
   MESSAGE PANE
   ========================================================================== */

.message-pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

.message-pane__empty, .message-pane__skeleton {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
}
.message-pane__empty img { margin: 0 auto 18px; opacity: 0.85; }
.message-pane__empty-title { font-family: var(--font-display); font-weight: 600; font-size: 16px; color: var(--text); margin-bottom: 6px; }
.message-pane__empty-text { font-size: 13px; }

.message-pane__skeleton { width: 100%; max-width: 560px; text-align: left; padding: 40px; }
.skeleton-line { height: 14px; margin-bottom: 10px; }
.skeleton-line--title { height: 22px; width: 60%; }
.skeleton-line--meta { width: 35%; margin-bottom: 24px; }
.skeleton-block { height: 220px; }

.message-detail { display: flex; flex-direction: column; min-height: 0; height: 100%; animation: fade-in var(--dur-med) var(--ease); }
.message-detail__header {
  padding: 22px 32px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.btn-back {
  display: none;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  font-size: 13.5px;
  padding: 0;
  margin-bottom: 14px;
}
.btn-back__icon {
  width: 8px; height: 8px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}
.message-detail__subject {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 10px;
  word-break: break-word;
}
.message-detail__meta { display: flex; align-items: center; gap: 10px; }
.message-detail__date { font-size: 12.5px; color: var(--text-faint); font-family: var(--font-mono); }

/* Signature element: postmark stamp badge */
.postmark {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--primary);
  border: 1.5px dashed var(--primary);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
  transform: rotate(-1.5deg);
}

.message-detail__body { flex: 1; min-height: 0; position: relative; }
.message-iframe { width: 100%; height: 100%; border: none; background: #fff; }
.message-plaintext {
  padding: 28px 32px;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  overflow-y: auto;
  height: 100%;
  margin: 0;
}

/* ==========================================================================
   MODAL
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 20, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: 20px;
  animation: fade-in var(--dur-fast) var(--ease);
}
.modal {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
  padding: 22px 24px 26px;
  animation: card-rise var(--dur-med) var(--ease);
}
.modal__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal__header h2 { font-family: var(--font-display); font-size: 16px; font-weight: 600; }

.shortcuts-list { display: flex; flex-direction: column; gap: 12px; }
.shortcuts-list > div { display: flex; align-items: center; gap: 12px; }
.shortcuts-list dt { display: flex; gap: 4px; min-width: 60px; }
.shortcuts-list dd { font-size: 13px; color: var(--text-muted); }
kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface-alt);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 2px 6px;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 900px) {
  .app-body { grid-template-columns: 1fr; }
  .app-header__menu { display: inline-flex; }
  .app-header__address { margin-left: 0; }
  .app-header__address-text { max-width: 140px; }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: min(88vw, 360px);
    z-index: 16;
    transform: translateX(-100%);
    transition: transform var(--dur-med) var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }

  .message-pane { grid-column: 1 / -1; }
  .btn-back { display: inline-flex; }

  .message-detail__header { padding: 16px 18px 14px; }
  .message-plaintext { padding: 18px; }
}

@media (max-width: 520px) {
  .auth-card { padding: 30px 22px 26px; }
  .auth-title { font-size: 22px; }
}
