*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Dark theme (default) */
:root {
  --bg: #0f0f0f;
  --bg2: #161616;
  --bg3: #1e1e1e;
  --bg4: #252525;
  --border: #2a2a2a;
  --border2: #333;
  --text: #e8e8e8;
  --text2: #a0a0a0;
  --text3: #666;
  --accent: #c47d4f;
  --accent2: #d4956a;
  --accent-dim: rgba(196, 125, 79, 0.12);
  --accent-dim2: rgba(196, 125, 79, 0.2);
  --red: #e05555;
  --red-dim: rgba(224, 85, 85, 0.12);
  --green: #4caf7d;
  --green-dim: rgba(76, 175, 125, 0.12);
  --blue: #5b9bd5;
  --blue-dim: rgba(91, 155, 213, 0.12);
  --radius: 10px;
  --radius2: 6px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --font: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── Light theme */
:root[data-theme="light"] {
  --bg: #f5f4f0;
  --bg2: #ffffff;
  --bg3: #f0eeea;
  --bg4: #e8e5e0;
  --border: #e0ddd8;
  --border2: #d0ccc6;
  --text: #1a1a1a;
  --text2: #555555;
  --text3: #999999;
  --accent: #b86e3a;
  --accent2: #c97d4a;
  --accent-dim: rgba(184, 110, 58, 0.1);
  --accent-dim2: rgba(184, 110, 58, 0.18);
  --red: #cc3333;
  --red-dim: rgba(204, 51, 51, 0.1);
  --green: #2e8a55;
  --green-dim: rgba(46, 138, 85, 0.1);
  --blue: #3a7bbf;
  --blue-dim: rgba(58, 123, 191, 0.1);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}

/* ── System preference: dark */
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #0f0f0f;
    --bg2: #161616;
    --bg3: #1e1e1e;
    --bg4: #252525;
    --border: #2a2a2a;
    --border2: #333;
    --text: #e8e8e8;
    --text2: #a0a0a0;
    --text3: #666;
    --accent: #c47d4f;
    --accent2: #d4956a;
    --accent-dim: rgba(196, 125, 79, 0.12);
    --accent-dim2: rgba(196, 125, 79, 0.2);
    --red: #e05555;
    --red-dim: rgba(224, 85, 85, 0.12);
    --green: #4caf7d;
    --green-dim: rgba(76, 175, 125, 0.12);
    --blue: #5b9bd5;
    --blue-dim: rgba(91, 155, 213, 0.12);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  }
}

/* ── System preference: light */
@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    --bg: #f5f4f0;
    --bg2: #ffffff;
    --bg3: #f0eeea;
    --bg4: #e8e5e0;
    --border: #e0ddd8;
    --border2: #d0ccc6;
    --text: #1a1a1a;
    --text2: #555555;
    --text3: #999999;
    --accent: #b86e3a;
    --accent2: #c97d4a;
    --accent-dim: rgba(184, 110, 58, 0.1);
    --accent-dim2: rgba(184, 110, 58, 0.18);
    --red: #cc3333;
    --red-dim: rgba(204, 51, 51, 0.1);
    --green: #2e8a55;
    --green-dim: rgba(46, 138, 85, 0.1);
    --blue: #3a7bbf;
    --blue-dim: rgba(58, 123, 191, 0.1);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  }
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  transition:
    background 0.2s,
    color 0.2s;
}

/* ── Scrollbar */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 99px;
}

/* ── Login page */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo-icon {
  width: 56px;
  height: 56px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  margin-bottom: 14px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.login-sub {
  font-size: 13px;
  color: var(--text2);
  margin-top: 4px;
}
.login-field {
  margin-bottom: 16px;
}

.login-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.login-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius2);
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
.login-input:focus {
  border-color: var(--accent);
}

.login-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius2);
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition:
    background 0.2s,
    opacity 0.2s;
}
.login-btn:hover {
  background: var(--accent2);
}
.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-error {
  background: var(--red-dim);
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: var(--radius2);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── App shell */
.app {
  display: grid;
  grid-template-columns: 220px 320px 1fr;
  grid-template-rows: 100vh;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar */
.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.sidebar-logo-icon {
  width: 32px;
  height: 32px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.sidebar-logo-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.sidebar-compose {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius2);
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 0.2s;
}
.sidebar-compose:hover {
  background: var(--accent2);
}

.sidebar-nav {
  padding: 12px 8px;
  flex: 1;
  overflow-y: auto;
}

.sidebar-section {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text3);
  padding: 8px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius2);
  cursor: pointer;
  font-size: 13px;
  color: var(--text2);
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  position: relative;
}
.nav-item:hover {
  background: var(--bg3);
  color: var(--text);
}
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}
.nav-item svg {
  flex-shrink: 0;
  opacity: 0.8;
}

.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 99px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: block;
  align-items: center;
  gap: 10px;
}

.admin-display {
  padding: 12px 16px;
  align-items: center;
  gap: 10px;
  display: flex;
}
.admin-avatar {
  width: 30px;
  height: 30px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.admin-info {
  flex: 1;
  overflow: hidden;
}
.admin-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.admin-role {
  font-size: 10px;
  color: var(--text3);
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}
.logout-btn:hover {
  color: var(--red);
}

/* ── Theme toggle (sits in sidebar footer) */
.theme-toggle {
  display: flex;
  align-items: center;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 99px;
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
}

.theme-btn {
  background: none;
  border: none;
  cursor: pointer;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  transition: all 0.15s;
  font-size: 13px;
}

.theme-btn:hover {
  color: var(--text2);
  background: var(--bg4);
}

.theme-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ── Email list panel */
.list-panel {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.list-toolbar {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-toolbar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.list-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.list-count {
  font-size: 11px;
  color: var(--text3);
  background: var(--bg3);
  padding: 2px 8px;
  border-radius: 99px;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 10px;
  color: var(--text3);
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius2);
  padding: 8px 10px 8px 32px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
.search-input:focus {
  border-color: var(--accent);
}
.search-input::placeholder {
  color: var(--text3);
}

.list-scroll {
  flex: 1;
  overflow-y: auto;
}

/* ── Read / Unread email distinction */
.email-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
  background: var(--bg2);
  border-left: 2px solid transparent;
}

.email-item .email-item-from {
  color: var(--text3);
  font-weight: 400;
}
.email-item .email-item-subject {
  color: var(--text3);
  font-weight: 400;
}
.email-item .email-item-preview {
  color: var(--text3);
  opacity: 0.7;
}

.email-item:hover {
  background: var(--bg4);
}

.email-item.unread {
  background: var(--bg3);
  border-left: 2px solid var(--accent);
}
.email-item.unread .email-item-from {
  color: var(--accent);
  font-weight: 700;
}
.email-item.unread .email-item-subject {
  color: var(--text);
  font-weight: 600;
}
.email-item.unread .email-item-preview {
  color: var(--text2);
  opacity: 1;
}
.email-item.unread:hover {
  background: var(--bg4);
  border-left-color: var(--accent2);
}

.email-item.active {
  background: var(--accent-dim);
  border-left: 2px solid var(--accent);
}
.email-item.active .email-item-from,
.email-item.active .email-item-subject {
  color: var(--accent);
  font-weight: 600;
}

.email-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.email-item-from {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.email-item-time {
  font-size: 11px;
  color: var(--text3);
  flex-shrink: 0;
}

.email-item-subject {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.email-item-preview {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-item-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
}

.badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 99px;
  font-weight: 600;
}
.badge-inbox {
  background: var(--accent-dim);
  color: var(--accent);
}
.badge-unread {
  background: var(--blue-dim);
  color: var(--blue);
}
.badge-att {
  background: var(--bg4);
  color: var(--text3);
}
.badge-sent {
  background: var(--green-dim);
  color: var(--green);
}
.badge-failed {
  background: var(--red-dim);
  color: var(--red);
}

.unread-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  box-shadow: 0 0 0 2px var(--accent-dim2);
}

.list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text3);
  font-size: 13px;
  gap: 8px;
}
.list-empty-icon {
  font-size: 32px;
}

/* ── Detail panel */
.detail-panel {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--text3);
}
.detail-empty-icon {
  font-size: 48px;
  opacity: 0.4;
}
.detail-empty-text {
  font-size: 14px;
}

.detail-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.detail-subject {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  border-radius: var(--radius2);
  padding: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.icon-btn:hover {
  background: var(--bg4);
  color: var(--text);
}
.icon-btn.danger:hover {
  background: var(--red-dim);
  border-color: var(--red);
  color: var(--red);
}

.detail-meta {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  font-size: 13px;
}
.meta-label {
  color: var(--text3);
  font-weight: 500;
}
.meta-value {
  color: var(--text2);
}

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.email-body-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.email-body-html {
  width: 100%;
  border: none;
  background: #fff;
  border-radius: var(--radius);
  min-height: 300px;
}

/* ── Attachments */
.attachments-section {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}
.attachments-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.attachments-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius2);
  padding: 7px 12px;
  font-size: 12px;
  color: var(--text2);
  text-decoration: none;
  transition: all 0.15s;
}
.attachment-chip:hover {
  background: var(--bg4);
  border-color: var(--accent);
  color: var(--accent);
}
.attachment-size {
  color: var(--text3);
  font-size: 11px;
}

/* ── Thread */
.thread-section {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
}
.thread-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.thread-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 8px;
}
.thread-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.thread-from {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}
.thread-time {
  font-size: 11px;
  color: var(--text3);
}
.thread-body {
  font-size: 13px;
  color: var(--text2);
  white-space: pre-wrap;
  line-height: 1.6;
}

/* ── Reply / Compose box */
.reply-box {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  background: var(--bg2);
}
.reply-box-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.reply-textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius2);
  padding: 12px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  resize: vertical;
  min-height: 100px;
  outline: none;
  transition: border-color 0.2s;
}
.reply-textarea:focus {
  border-color: var(--accent);
}

.reply-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  gap: 10px;
}
.reply-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.attach-btn {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  border-radius: var(--radius2);
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}
.attach-btn:hover {
  background: var(--bg4);
  border-color: var(--accent);
  color: var(--accent);
}

.attach-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.attach-preview-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 99px;
  padding: 3px 10px 3px 8px;
  font-size: 11px;
  color: var(--text2);
}

.attach-remove {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  margin-left: 2px;
  transition: color 0.15s;
}
.attach-remove:hover {
  color: var(--red);
}

.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius2);
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: background 0.2s;
  white-space: nowrap;
}
.send-btn:hover {
  background: var(--accent2);
}
.send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ── Compose modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-size: 15px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s;
}
.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 20px;
}

.field {
  margin-bottom: 14px;
}
.field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 5px;
}

.field-input,
.field-select,
.field-textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius2);
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}
.field-input:focus,
.field-select:focus,
.field-textarea:focus {
  border-color: var(--accent);
}
.field-textarea {
  resize: vertical;
  min-height: 140px;
}
.field-select option {
  background: var(--bg3);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.btn-secondary {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  border-radius: var(--radius2);
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:hover {
  background: var(--bg4);
  color: var(--text);
}

/* ── Toast */
.toast-wrap {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
  min-width: 260px;
}
.toast.success {
  border-left: 3px solid var(--green);
}
.toast.error {
  border-left: 3px solid var(--red);
}
.toast.info {
  border-left: 3px solid var(--blue);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ── Loading */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Stats bar */
.stats-bar {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text3);
}
.stat-chip b {
  color: var(--text);
}

/* ── Mobile Navigation Toggle */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  background: var(--accent);
  border: none;
  color: white;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow);
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition:
    transform 0.2s,
    background 0.2s;
}
.mobile-menu-toggle:hover {
  transform: scale(1.05);
  background: var(--accent2);
}
.mobile-menu-toggle:active {
  transform: scale(0.95);
}

/* Mobile Back Button */
.mobile-back-btn {
  display: none;
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  gap: 12px;
  z-index: 15;
  backdrop-filter: blur(10px);
}
.mobile-back-btn button {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius2);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.2s;
}
.mobile-back-btn button:hover {
  background: var(--bg4);
}

/* Sidebar Overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 140;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.active {
  display: block;
}

/* ── Tablet Landscape */
@media (max-width: 1024px) {
  .app {
    grid-template-columns: 200px 320px 1fr;
  }
  .email-item-from {
    max-width: 150px;
  }
  .detail-header {
    padding: 14px 20px;
  }
  .detail-subject {
    font-size: 17px;
  }
  .detail-meta {
    padding: 12px 20px;
  }
  .detail-body {
    padding: 20px;
  }
}

/* ── Tablet Portrait */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    position: relative;
    overflow: hidden;
  }

  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    width: 280px;
    height: 100vh;
    z-index: 150;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow);
  }
  .sidebar.mobile-open {
    left: 0;
  }

  .list-panel {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100vh;
    z-index: 10;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg2);
  }
  .list-panel.hide-list {
    transform: translateX(-100%);
  }

  .detail-panel {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100vh;
    z-index: 20;
    background: var(--bg);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateX(100%);
    overflow-y: auto;
  }
  .detail-panel.show-detail {
    transform: translateX(0);
  }

  .mobile-menu-toggle {
    display: flex;
  }

  .list-toolbar {
    padding: 12px 16px;
  }
  .list-title {
    font-size: 16px;
  }

  .stats-bar {
    padding: 8px 12px;
    gap: 8px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .stat-chip {
    flex-shrink: 0;
  }

  .email-item-from {
    max-width: 200px;
    font-size: 13px;
  }
  .email-item-subject {
    font-size: 12px;
  }
  .email-item-preview {
    font-size: 11px;
  }

  .detail-header {
    padding: 16px;
    gap: 12px;
  }
  .detail-subject {
    font-size: 16px;
    line-height: 1.4;
  }
  .icon-btn {
    padding: 8px;
    min-width: 34px;
    min-height: 34px;
  }

  .detail-meta {
    padding: 12px 16px;
    gap: 8px 12px;
    font-size: 12px;
  }
  .detail-body {
    padding: 16px;
  }
  .email-body-text {
    font-size: 14px;
    line-height: 1.6;
  }

  .attachments-section,
  .thread-section,
  .reply-box {
    padding: 12px 16px;
  }
  .attachment-chip {
    padding: 6px 10px;
    font-size: 11px;
  }
  .thread-item {
    padding: 12px;
  }
  .thread-from {
    font-size: 12px;
  }
  .thread-body {
    font-size: 12px;
  }

  .reply-textarea {
    font-size: 13px;
    min-height: 90px;
  }
  .reply-footer {
    flex-wrap: wrap;
  }
  .reply-left {
    flex: 1;
  }
  .send-btn {
    padding: 8px 16px;
    font-size: 12px;
  }

  .toast-wrap {
    bottom: 80px;
    right: 16px;
    left: 16px;
  }
  .toast {
    width: auto;
    font-size: 12px;
    padding: 10px 14px;
  }

  .modal {
    max-width: 94%;
    max-height: 90vh;
    margin: 20px;
  }
  .modal-body {
    padding: 16px;
  }
  .field-input,
  .field-select,
  .field-textarea {
    font-size: 14px;
  }

  /* Mobile: close button becomes "← Back" */
  #close-detail-btn {
    background: var(--bg4);
    border-color: var(--accent);
    color: var(--accent);
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    gap: 6px;
  }
  #close-detail-btn::before {
    content: "← Back";
    font-size: 13px;
  }
  #close-detail-btn svg {
    display: none;
  }
}

/* ── Small Mobile */
@media (max-width: 480px) {
  .login-card {
    margin: 20px;
    padding: 28px 20px;
  }
  .login-title {
    font-size: 20px;
  }
  .email-item-from {
    max-width: 140px;
    font-size: 12px;
  }
  .email-item-time {
    font-size: 10px;
  }
  .badge {
    font-size: 9px;
    padding: 2px 6px;
  }
  .detail-subject {
    font-size: 15px;
  }
  .detail-meta {
    gap: 6px 8px;
    font-size: 11px;
  }
  .thread-item-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }
  .icon-btn svg {
    width: 13px;
    height: 13px;
  }
  .mobile-menu-toggle {
    width: 45px;
    height: 45px;
    font-size: 20px;
    bottom: 15px;
    right: 15px;
  }
}

/* ── Landscape */
@media (max-width: 768px) and (orientation: landscape) {
  .sidebar {
    width: 260px;
  }
  .reply-textarea {
    min-height: 70px;
  }
  .modal {
    max-height: 85vh;
  }
  .modal-body {
    max-height: calc(85vh - 120px);
    overflow-y: auto;
  }
}

/* ── Touch */
@media (hover: none) and (pointer: coarse) {
  .nav-item,
  .email-item,
  .icon-btn,
  .send-btn,
  .attach-btn,
  .btn-secondary,
  .sidebar-compose,
  .attachment-chip {
    -webkit-tap-highlight-color: transparent;
  }
  .email-item:active,
  .nav-item:active {
    opacity: 0.7;
  }
  .nav-item {
    padding: 12px;
  }
  .email-item {
    padding: 14px;
  }
  .icon-btn {
    padding: 10px;
    min-width: 38px;
    min-height: 38px;
  }
  .send-btn,
  .attach-btn,
  .btn-secondary {
    padding: 10px 18px;
  }
  .sidebar-compose {
    padding: 11px;
  }
}

/* ── Reply section */
.reply-section {
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  background: var(--bg2);
}

.reply-toggle-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  border-radius: var(--radius2);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.reply-toggle-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.reply-box {
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 10px;
  background: var(--bg3);
  animation: fadeDown 0.15s ease;
}

@keyframes fadeDown {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.reply-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.reply-collapse-btn {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s;
  line-height: 1;
}
.reply-collapse-btn:hover {
  color: var(--red);
}

/* Mobile */
@media (max-width: 768px) {
  .reply-section {
    padding: 12px 16px;
  }
  .reply-toggle-btn {
    width: 100%;
    justify-content: center;
  }
}
