:root {
  --green: #0b6e4f;
  --green-2: #e3f1ec;
  --bg: #f6f8fc;
  --panel: #fff;
  --line: #e3e6ea;
  --text: #1f2328;
  --muted: #5f6368;
  --unread: #0d1b2a;
  --danger: #c62828;
  --radius: 12px;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--green); }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Đăng nhập ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 380px; background: var(--panel); border-radius: 16px; padding: 32px; box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.login h1 { margin: 0 0 4px; font-size: 22px; color: var(--green); }
.login p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 14px; }
.field input, .field textarea, .field select { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--green); border-color: transparent; }
.addr-input { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.addr-input input { border: 0; flex: 1; min-width: 0; }
.addr-input span { padding: 0 12px; color: var(--muted); background: #f3f4f6; align-self: stretch; display: flex; align-items: center; }
.btn { border: 0; border-radius: 999px; padding: 9px 18px; background: #eef0f3; }
.btn:hover { filter: brightness(.96); }
.btn.primary { background: var(--green); color: #fff; }
.btn.danger { background: #fde8e8; color: var(--danger); }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin-bottom: 8px; }
.ok { color: var(--green); font-size: 14px; }

/* ---------- Khung chính ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; grid-template-rows: 60px 1fr; height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 16px; }
.brand { display: flex; align-items: center; gap: 10px; width: 224px; font-weight: 600; color: var(--green); font-size: 18px; }
.brand .logo { width: 32px; height: 32px; border-radius: 8px; background: var(--green); color: #fff; display: grid; place-items: center; font-size: 16px; }
.menu-btn { display: none; border: 0; background: none; font-size: 22px; padding: 6px 8px; }
.search { flex: 1; max-width: 720px; }
.search input { width: 100%; padding: 11px 18px; border-radius: 999px; border: 0; background: #e9eef6; }
.search input:focus { outline: none; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.me { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 600; flex: none; }
.me-menu { position: relative; }
.me-menu .dropdown { position: absolute; right: 0; top: 42px; background: #fff; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.15); min-width: 220px; z-index: 30; padding: 8px 0; }
.dropdown .who { padding: 8px 16px 10px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.dropdown button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 16px; }
.dropdown button:hover { background: #f1f3f4; }

.sidebar { padding: 8px 12px 8px 8px; overflow-y: auto; }
.compose-btn { display: inline-flex; align-items: center; gap: 10px; padding: 16px 22px; border-radius: 16px; border: 0; background: #c2e7ff; font-weight: 600; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.compose-btn:hover { box-shadow: 0 2px 6px rgba(0,0,0,.18); }
.nav a { display: flex; align-items: center; gap: 14px; padding: 7px 14px 7px 18px; border-radius: 0 999px 999px 0; text-decoration: none; color: var(--text); font-size: 14px; }
.nav a:hover { background: #e8eaed; }
.nav a.active { background: #d3e3fd; font-weight: 700; }
.nav a .count { margin-left: auto; font-size: 12px; font-weight: 700; }
.nav .ico { width: 20px; text-align: center; }
.nav hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0 10px 18px; }

.main { background: var(--panel); border-radius: var(--radius); margin: 0 16px 16px 0; overflow: hidden; display: flex; min-height: 0; }
.list-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.main.reading .list-pane { flex: 0 0 40%; max-width: 520px; border-right: 1px solid var(--line); }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--line); min-height: 48px; font-size: 13px; color: var(--muted); }
.toolbar .spacer { flex: 1; }
.icon-btn { border: 0; background: none; width: 36px; height: 36px; border-radius: 50%; font-size: 17px; color: var(--muted); }
.icon-btn:hover { background: #eceff1; color: var(--text); }
.list { overflow-y: auto; flex: 1; }
.row { display: grid; grid-template-columns: 28px 180px 1fr auto; align-items: center; gap: 8px; padding: 0 14px; height: 42px; border-bottom: 1px solid #f1f3f4; cursor: pointer; font-size: 14px; }
.row:hover { box-shadow: inset 1px 0 0 #dadce0, inset -1px 0 0 #dadce0, 0 1px 2px rgba(60,64,67,.2); z-index: 1; position: relative; }
.row.unread { background: #fff; font-weight: 700; color: var(--unread); }
.row.read { background: #f8fafd; }
.row.selected { background: #c2dbff; }
.row .from, .row .subj { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .subj .snip { color: var(--muted); font-weight: 400; }
.row .date { font-size: 12px; white-space: nowrap; }
.star { border: 0; background: none; font-size: 17px; color: #c4c7c5; padding: 0; }
.star.on { color: #f4b400; }
.main.reading .row { grid-template-columns: 28px 1fr auto; grid-template-rows: auto auto; height: auto; padding: 8px 14px; }
.main.reading .row .from { grid-column: 2; }
.main.reading .row .date { grid-column: 3; grid-row: 1; }
.main.reading .row .subj { grid-column: 2 / 4; }
.empty { padding: 60px 20px; text-align: center; color: var(--muted); }
.more { padding: 12px; text-align: center; }

.reader { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.reader-head { padding: 16px 24px 8px; border-bottom: 1px solid var(--line); }
.reader-head h2 { margin: 0 0 12px; font-size: 21px; font-weight: 400; word-break: break-word; }
.sender { display: flex; gap: 12px; align-items: flex-start; }
.sender .who { flex: 1; min-width: 0; font-size: 14px; }
.sender .who b { font-weight: 700; }
.sender .who .addr { color: var(--muted); font-size: 12px; }
.sender .who .rcpt { color: var(--muted); font-size: 12px; margin-top: 2px; word-break: break-all; }
.sender .when { font-size: 12px; color: var(--muted); white-space: nowrap; }
.reader-actions { display: flex; gap: 8px; padding: 10px 24px; flex-wrap: wrap; align-items: center; border-bottom: 1px solid var(--line); }
.notice { background: #fff8e1; color: #6d4c00; font-size: 13px; padding: 8px 24px; display: flex; gap: 10px; align-items: center; }
.body-frame { flex: 1; border: 0; width: 100%; min-height: 300px; background: #fff; }
.plain { flex: 1; overflow: auto; padding: 16px 24px; white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.5; margin: 0; font-family: inherit; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 24px; border-top: 1px solid var(--line); }
.att { display: inline-flex; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 13px; text-decoration: none; color: var(--text); max-width: 260px; }
.att:hover { background: #f6f8fc; }
.att .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .size { color: var(--muted); font-size: 12px; flex: none; }

/* ---------- Soạn thư ---------- */
.compose { position: fixed; right: 24px; bottom: 0; width: 560px; max-width: 100vw; height: 560px; max-height: 92vh; background: #fff; border-radius: 12px 12px 0 0; box-shadow: 0 8px 30px rgba(0,0,0,.28); display: flex; flex-direction: column; z-index: 50; }
.compose.min { height: auto; }
.compose.min .compose-body { display: none; }
.compose-head { background: #f2f6fc; padding: 10px 14px; border-radius: 12px 12px 0 0; display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; cursor: pointer; }
.compose-head .spacer { flex: 1; }
.compose-head button { border: 0; background: none; font-size: 15px; width: 28px; height: 28px; border-radius: 6px; }
.compose-head button:hover { background: #e2e8f0; }
.compose-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.cline { display: flex; align-items: center; border-bottom: 1px solid var(--line); padding: 0 14px; font-size: 14px; }
.cline label { color: var(--muted); width: 54px; flex: none; }
.cline input { flex: 1; border: 0; padding: 10px 0; outline: none; min-width: 0; }
.cline .link { border: 0; background: none; color: var(--muted); font-size: 13px; }
.compose textarea { flex: 1; border: 0; padding: 12px 14px; resize: none; outline: none; font-size: 14px; line-height: 1.5; }
.compose-foot { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.compose-foot .files { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; }
.chip { background: #eef0f3; border-radius: 999px; padding: 3px 10px; display: inline-flex; gap: 6px; align-items: center; }
.chip button { border: 0; background: none; padding: 0; }
.compose .error { margin: 0; }

/* ---------- Trang quản trị / cài đặt ---------- */
.page { flex: 1; overflow-y: auto; padding: 24px; }
.page h2 { margin-top: 0; font-weight: 500; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 20px; max-width: 900px; }
.card h3 { margin: 0 0 14px; font-size: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
.tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--green-2); color: var(--green); margin-left: 6px; }
.tag.off { background: #fde8e8; color: var(--danger); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.toast { position: fixed; left: 24px; bottom: 24px; background: #323232; color: #fff; padding: 12px 18px; border-radius: 6px; font-size: 14px; z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,.3); }

/* ---------- Điện thoại ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .menu-btn { display: block; }
  .brand { width: auto; }
  .brand .label { display: none; }
  .sidebar { position: fixed; inset: 60px auto 0 0; width: 260px; background: var(--bg); z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: 2px 0 12px rgba(0,0,0,.15); }
  .shell.nav-open .sidebar { transform: none; }
  .main { margin: 0; border-radius: 0; }
  .main.reading .list-pane { display: none; }
  .row { grid-template-columns: 28px 1fr auto; grid-template-rows: auto auto; height: auto; padding: 10px 12px; }
  .row .from { grid-column: 2; }
  .row .date { grid-column: 3; grid-row: 1; }
  .row .subj { grid-column: 2 / 4; }
  .compose { right: 0; width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; }
  .grid2 { grid-template-columns: 1fr; }
  .me .name { display: none; }
  .reader-head, .reader-actions, .atts, .plain { padding-left: 14px; padding-right: 14px; }
}
