@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&family=Silkscreen&display=swap');
@import 'tokens.css';

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; font-family: var(--font-ui); background: var(--c-bg); color: var(--c-text); font-size: 14px; line-height: 1.5; }

/* ── AUTH ── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--c-bg);
}
.auth-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}
.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}
.auth-wordmark {
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 2px;
  color: var(--c-text);
}
.auth-subtitle {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--c-text-2);
  margin-top: 4px;
}

/* ── APP SHELL ── */
#app { display: none; height: 100vh; flex-direction: column; }
#app.active { display: flex; }

/* ── TOP BAR ── */
.top-bar {
  height: var(--header-h);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
}
.logo {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--c-text);
  flex-shrink: 0;
}
.search-wrap {
  flex: 1;
  max-width: 460px;
}
.search-wrap input {
  width: 100%;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 7px 12px;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--c-text);
  outline: none;
  transition: border-color .15s;
}
.search-wrap input:focus { border-color: var(--c-accent); }
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  margin-left: auto;
}
.sys-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--c-text-2);
}
.sys-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #16a34a;
  display: inline-block;
  flex-shrink: 0;
}
.sys-clock {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--c-text-3);
}

/* ── MAIN LAYOUT ── */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.compose-btn {
  margin: 12px;
  padding: 10px 16px;
  background: var(--c-accent);
  color: var(--c-bg);
  border: none;
  border-radius: var(--r-md);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  width: calc(100% - 24px);
  letter-spacing: .3px;
  text-align: center;
  transition: background .1s;
}
.compose-btn:hover { background: var(--c-accent-hover); }

.folder-nav {
  padding: 8px 0;
  flex: 1;
  overflow-y: auto;
}
.folder-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--c-text-2);
  text-align: left;
  border-radius: 0;
  transition: background .1s, color .1s;
}
.folder-item:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
}
.folder-item.active {
  background: var(--c-surface-2);
  color: var(--c-text);
  font-weight: 500;
}
.folder-item .fi-icon {
  font-size: 14px;
  width: 18px;
  flex-shrink: 0;
  text-align: center;
}
.folder-item .fi-name { flex: 1; }
.folder-item .fi-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--c-text-3);
}
.folder-item.vault-locked .fi-icon { color: var(--c-text-3); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
}
#user-email {
  font-family: var(--font-mono);
  color: var(--c-text-3);
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}
#logout-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--c-text-3);
  font-size: 11px;
  font-family: var(--font-ui);
  padding: 0;
  transition: color .1s;
}
#logout-btn:hover { color: var(--c-danger); }

/* ── MESSAGE LIST PANE ── */
.message-list-pane {
  width: var(--list-w);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}
.pane-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--c-border);
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
#pane-count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--c-text-3);
  font-weight: 400;
}
#message-list { flex: 1; overflow-y: auto; }
.message-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--c-border);
  cursor: pointer;
  transition: background .1s;
}
.message-item:hover { background: var(--c-surface-2); }
.message-item.active { background: var(--c-surface-3); }
.message-item.unread .msg-subject { font-weight: 600; color: var(--c-unread); }
.msg-from {
  font-size: 12px;
  font-weight: 500;
  color: var(--c-text);
  margin-bottom: 3px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.msg-date {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--c-text-3);
  font-weight: 400;
}
.msg-subject {
  font-size: 13px;
  color: var(--c-text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── READING PANE WRAP ── */
.reading-pane-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
#msg-toolbar {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
  flex-wrap: wrap;
  min-height: 43px;
  background: var(--c-surface);
  align-items: center;
}
#reading-pane {
  flex: 1;
  overflow-y: auto;
  background: var(--c-surface);
}
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-text-3);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1px;
  height: 100%;
}

/* ── READING PANE CONTENT ── */
.msg-header {
  padding: 24px 28px 20px;
  border-bottom: 1px solid var(--c-border);
}
.msg-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--c-text);
}
.msg-meta {
  font-size: 12px;
  color: var(--c-text-2);
  line-height: 2;
}
.msg-actions {
  padding: 12px 28px;
  border-bottom: 1px solid var(--c-border);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.msg-body {
  padding: 24px 28px;
  font-size: 14px;
  line-height: 1.8;
  color: var(--c-text);
}
.msg-body pre {
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
}

/* ── COMPOSE MODAL ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 24px;
  pointer-events: none;
}
.modal-overlay.open {
  display: flex;
  pointer-events: auto;
}
.compose-modal {
  width: 560px;
  max-height: 78vh;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
}
.compose-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}
.compose-header button {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--c-text-2);
  font-size: 18px;
  line-height: 1;
  padding: 0;
}
.compose-header button:hover { color: var(--c-text); }
.compose-fields {
  padding: 12px 16px;
  border-bottom: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.compose-fields input {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--c-border);
  padding: 4px 0;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--c-text);
  outline: none;
}
.compose-fields input:focus { border-bottom-color: var(--c-accent); }
.compose-body {
  flex: 1;
  min-height: 200px;
  padding: 12px 16px;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--c-text);
  resize: none;
  border: none;
  outline: none;
  background: transparent;
}
.compose-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--c-border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ── VAULT MODAL ── */
.vault-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}
.vault-overlay.open { display: flex; }
.vault-modal {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: 40px;
  width: 360px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-md);
}
.vault-icon { font-size: 36px; }
.vault-modal h2 { font-size: 18px; font-weight: 600; color: var(--c-text); }
.vault-modal p { font-size: 13px; color: var(--c-text-2); }
#vault-pass {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--c-text);
  outline: none;
  transition: border-color .15s;
}
#vault-pass:focus { border-color: var(--c-accent); }
.vault-error {
  font-size: 12px;
  color: var(--c-danger);
  min-height: 16px;
}
.vault-modal .btn { width: 100%; }

/* ── BUTTONS ── */
.btn {
  padding: 7px 16px;
  border-radius: var(--r-md);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .1s, border-color .1s, color .1s;
}
.btn-primary { background: var(--c-accent); color: var(--c-bg); border-color: var(--c-accent); }
.btn-primary:hover { background: var(--c-accent-hover); border-color: var(--c-accent-hover); }
.btn-ghost { background: transparent; color: var(--c-text-2); border-color: var(--c-border); }
.btn-ghost:hover { background: var(--c-surface-2); color: var(--c-text); }
.btn-danger { background: transparent; color: var(--c-danger); border-color: var(--c-danger); }
.btn-danger:hover { background: var(--c-danger); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── THEME TOGGLE ── */
.theme-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--c-text-2);
  font-size: 16px;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  line-height: 1;
}
.theme-btn:hover { background: var(--c-surface-2); }

/* ── FORM ELEMENTS ── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--c-text-2);
  margin-bottom: 6px;
  letter-spacing: .5px;
  text-transform: uppercase;
  font-family: var(--font-mono);
}
.form-group input {
  width: 100%;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 8px 12px;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--c-text);
  outline: none;
  transition: border-color .15s;
}
.form-group input:focus { border-color: var(--c-accent); }
.form-error { font-size: 12px; color: var(--c-danger); margin-top: 8px; min-height: 16px; }

/* ── TOAST ── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: slideIn .2s ease;
  font-family: var(--font-ui);
}
.toast.error { border-color: var(--c-danger); color: var(--c-danger); }
.toast.success { border-color: var(--c-success); color: var(--c-success); }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── LOADING ── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── PAGINATION ── */
#pagination {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  justify-content: center;
  border-top: 1px solid var(--c-border);
  flex-shrink: 0;
}
#pagination:empty { display: none; }
