/* ============================================================
   Gold Mail — giao diện webmail (tông vàng gold + xanh navy)
   ============================================================ */
:root {
  --gold: #c8a04a;
  --gold-light: #e4c877;
  --gold-dark: #a9812f;
  --navy: #10233a;
  --navy-2: #172f4d;
  --ink: #1d2733;
  --muted: #6b7785;
  --line: #e6e9ee;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --unread: #f0f5ff;
  --danger: #d64545;
  --ok: #2e9e5b;
  --shadow: 0 6px 24px rgba(16, 35, 58, .12);
  --radius: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--ink); font-size: 14px; }
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.screen { height: 100vh; width: 100%; }
.center { display: flex; align-items: center; justify-content: center; }

/* --- Spinner --- */
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--gold);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Đăng nhập ============ */
#screen-auth {
  background: radial-gradient(1200px 600px at 20% -10%, var(--navy-2), var(--navy));
}
.auth-card {
  width: 380px; max-width: 92vw; background: var(--surface);
  border-radius: 16px; padding: 32px; box-shadow: var(--shadow);
}
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.logo-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 12px; font-size: 24px;
  background: linear-gradient(135deg, var(--gold-light), var(--gold-dark));
  color: var(--navy);
}
.logo-mark.sm { width: 30px; height: 30px; font-size: 16px; border-radius: 8px; }
.logo-title { font-size: 20px; font-weight: 700; color: var(--navy); }
.logo-sub { font-size: 12px; color: var(--muted); letter-spacing: .5px; }
.auth-card h2 { font-size: 22px; margin-bottom: 4px; color: var(--navy); }
.auth-card p { margin-bottom: 18px; font-size: 13px; }
.auth-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.auth-card input {
  width: 100%; margin-top: 6px; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 9px; background: #fbfcfe;
}
.auth-card input:focus { outline: 2px solid var(--gold-light); border-color: var(--gold); }

/* ============ Nút ============ */
.btn {
  border: none; border-radius: 9px; padding: 10px 16px;
  font-size: 14px; font-weight: 600; transition: .15s;
}
.btn-primary { background: linear-gradient(135deg, var(--gold), var(--gold-dark)); color: #2a1e00; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; color: var(--navy); }
.btn-ghost:hover { background: #eef1f5; }
.btn-block { width: 100%; margin-top: 6px; }
.form-error { background: #fdecec; color: var(--danger); padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }

/* ============ Thanh trên cùng ============ */
.topbar {
  height: 56px; background: var(--navy); color: #fff;
  display: flex; align-items: center; gap: 16px; padding: 0 16px;
}
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.search { flex: 1; max-width: 560px; }
.search input {
  width: 100%; padding: 9px 14px; border-radius: 20px; border: none;
  background: rgba(255,255,255,.14); color: #fff;
}
.search input::placeholder { color: rgba(255,255,255,.6); }
.search input:focus { outline: 2px solid var(--gold); background: rgba(255,255,255,.2); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: transparent; border: none; color: inherit; font-size: 18px;
  width: 38px; height: 38px; border-radius: 8px;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--gold);
  background: var(--gold); color: var(--navy); font-weight: 700; font-size: 15px;
}
.user-menu { position: relative; }
.dropdown {
  position: absolute; right: 0; top: 46px; width: 240px; background: #fff; color: var(--ink);
  border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; z-index: 40;
}
.dd-head { padding: 14px 16px; background: #f7f9fc; border-bottom: 1px solid var(--line); }
.dd-name { font-weight: 700; }
.dd-email { font-size: 12px; color: var(--muted); }
.dd-item { display: block; width: 100%; text-align: left; padding: 12px 16px; background: none; border: none; font-size: 14px; }
.dd-item:hover { background: #f2f5f9; }

/* ============ Bố cục 3 cột ============ */
.layout { display: flex; height: calc(100vh - 56px); }
.sidebar {
  width: 220px; background: #fff; border-right: 1px solid var(--line);
  padding: 16px 12px; flex-shrink: 0; overflow-y: auto;
}
.btn-compose { width: 100%; margin-bottom: 16px; padding: 12px; }
.folders { display: flex; flex-direction: column; gap: 2px; }
.folder {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 9px; border: none; background: none; text-align: left;
  font-size: 14px; color: var(--ink); width: 100%;
}
.folder:hover { background: #f2f5f9; }
.folder.active { background: var(--unread); color: var(--navy); font-weight: 600; }
.folder .f-icon { width: 20px; text-align: center; }
.folder .f-name { flex: 1; }
.folder .f-badge {
  background: var(--gold); color: var(--navy); font-size: 11px; font-weight: 700;
  padding: 1px 8px; border-radius: 10px;
}

/* --- Danh sách thư --- */
.list-pane {
  width: 380px; flex-shrink: 0; background: #fff;
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
}
.list-head {
  padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700;
  color: var(--navy); display: flex; justify-content: space-between; align-items: baseline;
}
.list-count { font-size: 12px; color: var(--muted); font-weight: 400; }
.msg-list { flex: 1; overflow-y: auto; }
.msg-item {
  padding: 12px 18px; border-bottom: 1px solid var(--line); cursor: pointer;
  display: flex; flex-direction: column; gap: 3px; border-left: 3px solid transparent;
}
.msg-item:hover { background: #f7f9fc; }
.msg-item.active { background: var(--unread); border-left-color: var(--gold); }
.msg-item.unread { background: #fbfdff; }
.msg-item.unread .mi-from, .msg-item.unread .mi-subject { font-weight: 700; }
.mi-row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.mi-from { color: var(--ink); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mi-date { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.mi-subject { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mi-preview { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mi-tags { display: flex; gap: 6px; align-items: center; }
.mi-star { color: #d9c07a; }
.mi-clip { color: var(--muted); font-size: 12px; }
.empty-list { padding: 40px 20px; text-align: center; color: var(--muted); }

/* --- Khung đọc --- */
.read-pane { flex: 1; background: #fff; overflow-y: auto; }
.read-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); gap: 12px; }
.read-empty-icon { font-size: 56px; opacity: .35; }
.read-content { padding: 24px 32px; max-width: 900px; }
.read-subject { font-size: 22px; color: var(--navy); margin-bottom: 16px; font-weight: 700; }
.read-meta { display: flex; align-items: center; gap: 12px; padding-bottom: 16px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.read-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--gold); color: var(--navy); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; flex-shrink: 0; }
.read-from-name { font-weight: 700; }
.read-from-addr { font-size: 12px; color: var(--muted); }
.read-to { font-size: 12px; color: var(--muted); margin-top: 2px; }
.read-date { margin-left: auto; font-size: 12px; color: var(--muted); }
.read-actions { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.read-body { line-height: 1.6; color: #222; word-wrap: break-word; }
.read-body img { max-width: 100%; height: auto; }
.read-body a { color: var(--gold-dark); }
.read-atts { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }
.read-atts h4 { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.att-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; margin: 0 8px 8px 0;
  background: #f4f6f9; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
  color: var(--ink); text-decoration: none;
}
.att-chip:hover { background: #eaeef3; }

/* ============ Modal soạn thư ============ */
.modal-overlay { position: fixed; inset: 0; background: rgba(16,35,58,.4); z-index: 60; display: flex; align-items: flex-end; justify-content: flex-end; padding: 0 24px 0 0; }
.compose {
  width: 620px; max-width: 96vw; height: 560px; max-height: 90vh; background: #fff;
  border-radius: 14px 14px 0 0; box-shadow: var(--shadow); display: flex; flex-direction: column;
  margin-bottom: 0;
}
.compose.minimized { height: 48px; }
.compose-head { background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 14px 14px 0 0; display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.compose-head .icon-btn { width: 30px; height: 30px; font-size: 16px; }
.compose-body { flex: 1; padding: 8px 16px; overflow-y: auto; display: flex; flex-direction: column; }
.compose.minimized .compose-body, .compose.minimized .compose-foot { display: none; }
.field { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.field label { width: 56px; color: var(--muted); font-size: 13px; }
.field input { flex: 1; border: none; padding: 11px 4px; }
.field input:focus { outline: none; }
#c-body { flex: 1; border: none; padding: 14px 4px; resize: none; line-height: 1.6; min-height: 160px; }
#c-body:focus { outline: none; }
.compose-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.compose-status { font-size: 12px; color: var(--muted); margin-left: 4px; }
.btn-discard { margin-left: auto; color: var(--danger); }
.attach-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 0; }
.attach-item { display: inline-flex; align-items: center; gap: 6px; background: #f4f6f9; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; }
.attach-item button { border: none; background: none; color: var(--danger); font-size: 14px; }

/* ============ Panel cài đặt / quản trị ============ */
.panel { width: 640px; max-width: 96vw; max-height: 86vh; margin: auto; background: #fff; border-radius: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.modal-overlay.center-modal { align-items: center; justify-content: center; padding: 24px; }
.panel-head { background: var(--navy); color: #fff; padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.panel-body { padding: 20px; overflow-y: auto; }
.panel-body h3 { font-size: 15px; margin: 4px 0 12px; color: var(--navy); }
.panel-body label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.panel-body input, .panel-body textarea { width: 100%; margin-top: 5px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.panel-body textarea { min-height: 90px; resize: vertical; }
.user-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.user-row .u-info { flex: 1; }
.user-row .u-email { font-weight: 600; }
.user-row .u-name { font-size: 12px; color: var(--muted); }
.badge-admin { background: var(--gold); color: var(--navy); font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 700; }
.mini-btn { padding: 6px 10px; font-size: 12px; border-radius: 7px; border: 1px solid var(--line); background: #fff; }
.mini-btn.danger { color: var(--danger); border-color: #f2c9c9; }
.add-user-form { background: #f7f9fc; border-radius: 10px; padding: 16px; margin-top: 16px; }
.row2 { display: flex; gap: 12px; }
.row2 > * { flex: 1; }

/* ============ Toast ============ */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 12px 22px; border-radius: 10px; box-shadow: var(--shadow); z-index: 90; font-size: 14px; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ============ Responsive ============ */
.only-mobile { display: none; }
@media (max-width: 900px) {
  .only-mobile { display: inline-flex; }
  .search { display: none; }
  .sidebar { position: fixed; top: 56px; left: 0; bottom: 0; z-index: 30; transform: translateX(-100%); transition: .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .list-pane { width: 100%; }
  .read-pane { position: fixed; inset: 56px 0 0 0; z-index: 20; transform: translateX(100%); transition: .2s; }
  .read-pane.open { transform: translateX(0); }
  .compose { width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; }
  .modal-overlay { padding: 0; }
}
