/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg:          #0a0a0f;
  --bg-card:     rgba(255, 255, 255, 0.04);
  --bg-hover:    rgba(255, 255, 255, 0.08);
  --bg-active:   rgba(99, 102, 241, 0.15);
  --border:      rgba(255, 255, 255, 0.08);
  --text:        #e4e4e7;
  --text-muted:  #71717a;
  --text-dim:    #52525b;
  --accent:      #6366f1;
  --accent-hover:#818cf8;
  --danger:      #ef4444;
  --star:        #fbbf24;
  --radius:      12px;
  --radius-sm:   8px;
  --glass:       blur(20px);
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Auth screen ──────────────────────────────────────────── */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at top, rgba(99, 102, 241, 0.08), transparent 50%),
              radial-gradient(ellipse at bottom, rgba(168, 85, 247, 0.05), transparent 50%),
              var(--bg);
}

.auth-card {
  width: 400px;
  max-width: 90vw;
  background: rgba(20, 20, 30, 0.6);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin-bottom: 32px;
  color: var(--accent);
}

.auth-logo h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--text);
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-tab.active {
  background: var(--accent);
  color: white;
}

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

.btn-quick {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  margin-bottom: 20px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-quick:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.btn-quick:active {
  transform: translateY(0);
}

.quick-result {
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 16px;
  font-size: 13px;
  display: none;
}

.quick-result.show {
  display: block;
}

.quick-result .qr-label {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.quick-result .qr-value {
  color: var(--text);
  font-family: monospace;
  font-size: 14px;
  margin-bottom: 8px;
  word-break: break-all;
}

.quick-result .qr-copy {
  background: var(--accent);
  border: none;
  color: white;
  padding: 6px 14px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.quick-result .qr-copy:hover {
  background: var(--accent-hover);
}

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

.auth-form input {
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.auth-form input:focus {
  border-color: var(--accent);
}

.auth-form input::placeholder {
  color: var(--text-dim);
}

.btn-primary {
  padding: 12px 20px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
}

.hidden {
  display: none !important;
}

/* ── App layout ───────────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: rgba(15, 15, 25, 0.6);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 20px;
  color: var(--accent);
}

.sidebar-header span {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.btn-compose {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  margin-bottom: 16px;
}

.btn-compose:hover {
  background: var(--accent-hover);
}

.folder-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.folder-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.folder-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.folder-item.active {
  background: var(--bg-active);
  color: var(--accent-hover);
}

.folder-item span:nth-child(2) {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}

.folder-count {
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.folder-item.active .folder-count {
  background: var(--accent);
  color: white;
}

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.user-info {
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 12px;
  word-break: break-all;
}

.btn-logout {
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ── Content area ─────────────────────────────────────────── */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Message list ─────────────────────────────────────────── */
.list-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.list-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.search-bar input {
  width: 260px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

.search-bar input:focus {
  border-color: var(--accent);
}

.search-bar input::placeholder {
  color: var(--text-dim);
}

.message-list {
  flex: 1;
  overflow-y: auto;
}

.message-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.message-item:hover {
  background: var(--bg-hover);
}

.message-item.unread {
  font-weight: 600;
}

.message-item.unread .message-sender,
.message-item.unread .message-subject {
  color: var(--text);
}

.message-star {
  color: var(--star);
  flex-shrink: 0;
  margin-top: 2px;
}

.message-star.empty {
  color: var(--text-dim);
  opacity: 0.4;
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-sender {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-subject {
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.message-preview {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-date {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
  margin-top: 2px;
}

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  margin-top: 6px;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  font-size: 15px;
}

/* ── Message reader ───────────────────────────────────────── */
.reader-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.reader-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

.btn-back {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: color 0.2s;
}

.btn-back:hover {
  color: var(--accent-hover);
}

.reader-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
}

.btn-icon.starred {
  color: var(--star);
  border-color: var(--star);
}

.reader-meta {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.reader-meta h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}

.reader-from {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 2px;
}

.reader-date {
  font-size: 12px;
  color: var(--text-dim);
}

.reader-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

.reader-body iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* ── Compose ──────────────────────────────────────────────── */
.compose-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 24px;
}

.compose-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.compose-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.btn-close-compose {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  transition: color 0.2s;
}

.btn-close-compose:hover {
  color: var(--danger);
}

.compose-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.compose-form input,
.compose-form textarea {
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.compose-form input:focus,
.compose-form textarea:focus {
  border-color: var(--accent);
}

.compose-form input::placeholder,
.compose-form textarea::placeholder {
  color: var(--text-dim);
}

.compose-form textarea {
  flex: 1;
  resize: none;
  line-height: 1.6;
}

.compose-form button {
  align-self: flex-end;
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -240px;
    z-index: 100;
    transition: left 0.3s;
  }

  .sidebar.open {
    left: 0;
  }

  .search-bar input {
    width: 140px;
  }

  .list-header {
    padding: 16px;
  }

  .message-item {
    padding: 14px 16px;
  }

  .reader-body {
    padding: 16px;
  }
}

/* ── Profile ──────────────────────────────────────────────── */
.profile-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 24px;
  overflow-y: auto;
}

.profile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.profile-header h2 {
  font-size: 20px;
  font-weight: 600;
}

.profile-body {
  max-width: 500px;
}

.profile-row {
  display: flex;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.profile-label {
  width: 120px;
  font-size: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.profile-value {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  word-break: break-all;
}

.profile-password {
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-password span {
  font-family: monospace;
  font-size: 14px;
}

.btn-show-pw, .btn-copy-pw {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-show-pw:hover, .btn-copy-pw:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
}

.btn-profile {
  width: 100%;
  padding: 8px;
  margin-bottom: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-profile:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
}

.profile-section {
  margin-top: 32px;
}

.profile-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
}

.change-pw-form {
  display: flex;
  gap: 10px;
}

.change-pw-form input {
  flex: 1;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.change-pw-form input:focus {
  border-color: var(--accent);
}

.reader-meta {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.reader-meta h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}

.reader-from {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 4px;
}

.reader-date {
  font-size: 12px;
  color: var(--text-dim);
}

/* ── Admin panel ──────────────────────────────────────────── */
.btn-admin {
  width: 100%;
  padding: 8px;
  margin-bottom: 8px;
  background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(168,85,247,0.2));
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent-hover);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-admin:hover {
  background: linear-gradient(135deg, rgba(99,102,241,0.3), rgba(168,85,247,0.3));
}

.admin-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 24px;
  overflow-y: auto;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.admin-header h2 {
  font-size: 20px;
  font-weight: 600;
}

.admin-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 28px;
  min-width: 140px;
  text-align: center;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent-hover);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 4px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
}

.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.admin-table tr:hover td {
  background: var(--bg-hover);
}

.admin-table .pw-cell {
  font-family: monospace;
  cursor: pointer;
}

.admin-table .pw-hidden {
  color: var(--text-dim);
}

.admin-action {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  margin-right: 4px;
  transition: all 0.2s;
}

.admin-action:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
}

.admin-action.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}
