:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --text-dim: #9aa1ad;
  --accent: #5b8cff;
  --accent-dim: #3a5bb8;
  --danger: #e5484d;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 0;
}
.sidebar.hidden { display: none; }

.sidebar-brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  padding: 0 20px 20px;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-link {
  display: block;
  padding: 10px 20px;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-link:hover { color: var(--text); background: var(--panel-2); }
.sidebar-link.active { color: var(--text); background: var(--panel-2); border-left-color: var(--accent); }

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-footer .user-email { font-size: 13px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-footer button { width: 100%; }

#app {
  flex: 1;
  min-width: 0;
  max-width: 980px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

.section-label {
  margin: 0 0 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.card-title { margin: 0 0 8px; font-size: 20px; font-weight: 600; color: var(--text); }
.page-title { margin: 0 0 20px; font-size: 22px; font-weight: 600; color: var(--text); }

.back-link-row { margin-bottom: 16px; }

.text-dim { color: var(--text-dim); }
.text-danger { color: var(--danger); }

.upload-status { margin-top: 10px; font-size: 13px; color: var(--text-dim); }

.user-info { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-dim); }

.upload-form { display: flex; flex-direction: column; gap: 14px; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 28px 20px;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover { border-color: var(--accent-dim); }
.dropzone.dragover { border-color: var(--accent); background: #1b2030; }
.dropzone:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.3); }

.dropzone-icon { font-size: 22px; }
.dropzone-text { font-size: 13px; color: var(--text-dim); }
.dropzone-text.has-file { color: var(--text); font-weight: 500; }

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

.upload-fields { display: flex; gap: 10px; }
.upload-fields input { flex: 1; }

input[type="text"], input[type="search"], input[type="email"], input[type="password"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.15s ease;
}

input::placeholder { color: var(--text-dim); opacity: 1; }

input:focus-visible, button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.3);
}

input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

input[type="file"] { color: var(--text-dim); font-size: 13px; }
input[type="file"]::file-selector-button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  margin-right: 12px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s ease;
}
input[type="file"]::file-selector-button:hover { background: var(--border); }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease;
}
button:hover { background: var(--accent-dim); }
button.secondary { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); padding: 6px 10px; font-size: 13px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.archive-list { list-style: none; margin: 0; padding: 0; }
.archive-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
  background: var(--panel-2);
}
.archive-item { transition: border-color 0.15s ease, background 0.15s ease; }
.archive-item:hover { border-color: var(--accent-dim); background: #20242e; }
.archive-main { display: flex; flex-direction: column; gap: 4px; cursor: pointer; flex: 1; }
.archive-name { font-weight: 600; font-size: 15px; }
.archive-meta { font-size: 12px; color: var(--text-dim); }
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge.ready { color: #4ade80; border-color: #244d33; }
.badge.processing { color: #facc15; border-color: #4d4324; }
.badge.error { color: var(--danger); border-color: #4d2426; }

.archive-actions { display: flex; align-items: center; gap: 10px; }

.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}
.search-row input { flex: 1; }

.search-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 16px;
  cursor: pointer;
}
.search-option input { cursor: pointer; }

.message-row {
  display: flex;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--panel-2);
}
.message-row { transition: border-color 0.15s ease, background 0.15s ease; }
.message-row:hover { border-color: var(--accent-dim); background: #20242e; }
.message-from { width: 200px; flex-shrink: 0; font-size: 13px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-main { flex: 1; min-width: 0; }
.message-subject { font-size: 14px; font-weight: 500; margin-bottom: 2px; }
.message-snippet { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-date { width: 130px; flex-shrink: 0; text-align: right; font-size: 12px; color: var(--text-dim); }
.attach-icon { margin-left: 6px; }

.pagination { display: flex; justify-content: center; gap: 10px; align-items: center; margin-top: 16px; }

.empty-state { text-align: center; color: var(--text-dim); padding: 40px 0; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 20px;
  overflow-y: auto;
  z-index: 20;
}
.overlay.hidden { display: none; }

.message-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 800px;
  width: 100%;
  padding: 28px;
  position: relative;
}

.close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: transparent;
  color: var(--text-dim);
  font-size: 22px;
  padding: 4px 10px;
}
.close-btn:hover { color: var(--text); background: var(--panel-2); }

.msg-header { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.msg-subject { font-size: 19px; font-weight: 600; margin-bottom: 10px; padding-right: 30px; }
.msg-field { font-size: 13px; color: var(--text-dim); margin-bottom: 2px; }
.msg-field b { color: var(--text); font-weight: 500; }

.msg-body iframe { width: 100%; border: none; min-height: 100px; }
.msg-body pre { white-space: pre-wrap; word-wrap: break-word; font-family: inherit; font-size: 14px; line-height: 1.5; }

.attachments-list { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  margin: 0 8px 8px 0;
  font-size: 13px;
}

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

.auth-screen { min-height: 70vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-brand { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 4px; }
.auth-subtitle { text-align: center; font-size: 13px; color: var(--text-dim); margin: 0 0 22px; }

.auth-tabs { display: flex; gap: 4px; background: var(--panel-2); border-radius: 8px; padding: 4px; }
.auth-tab { flex: 1; background: transparent; color: var(--text-dim); }
.auth-tab.active { background: var(--accent); color: #fff; }
.auth-form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.auth-form input:not([type="checkbox"]) { width: 100%; }
.narrow-form { max-width: 380px; margin-top: 0; }
.auth-error { margin-top: 10px; font-size: 13px; color: var(--danger); min-height: 16px; }
.auth-note { margin-top: 10px; font-size: 12px; color: var(--text-dim); text-align: center; }
