:root {
  --brand: #c8553d;
  --brand-dark: #a3422f;
  --brand-soft: #fbe9e4;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1f2937;
  --text-muted: #6b7280;
  --hover: #f1f3f5;
  --selected: #fbe9e4;
  --unread-bg: #ffffff;
  --read-bg: #f6f8fb;
  --danger: #d33;
  --success: #16a34a;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: var(--text); background: var(--bg); }
body { overflow: hidden; }

button, input, textarea, select { font-family: inherit; font-size: 14px; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input, textarea, select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Login ---- */
.login-page { display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg, #c8553d 0%, #6b2c20 100%); }
.login-card { background: var(--surface); padding: 36px 40px; border-radius: 12px; width: 360px; box-shadow: 0 18px 48px rgba(0,0,0,.18); }
.login-card h1 { margin: 0 0 4px; font-size: 24px; color: var(--brand); }
.login-card .subtitle { color: var(--text-muted); margin-bottom: 22px; font-size: 13px; }
.login-card label { display: block; font-size: 12px; color: var(--text-muted); margin: 12px 0 4px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; background: var(--brand); color: white; padding: 10px; border-radius: 6px; margin-top: 18px; font-weight: 600; font-size: 14px; }
.login-card button:hover { background: var(--brand-dark); }
.login-card .err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---- App shell ---- */
.shell { display: grid; grid-template-rows: 56px 1fr; height: 100vh; }
.topbar { display: flex; align-items: center; padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--brand); font-size: 18px; }
.topbar .brand-mark { width: 32px; height: 32px; background: var(--brand); color: white; border-radius: 8px; display: grid; place-items: center; font-weight: 800; }
.topbar .search { flex: 1; max-width: 720px; margin: 0 24px; }
.topbar .search input { width: 100%; background: var(--hover); border-color: transparent; }
.topbar .user-pill { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-radius: 24px; cursor: pointer; }
.topbar .user-pill:hover { background: var(--hover); }
.topbar .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: white; display: grid; place-items: center; font-weight: 700; }

.main { display: grid; grid-template-columns: 240px 1fr; overflow: hidden; }
.sidebar { background: var(--bg); padding: 12px 8px; overflow-y: auto; border-right: 1px solid var(--border); }
.compose-btn { background: var(--brand); color: white; padding: 12px 18px; border-radius: 24px; font-weight: 600; display: flex; align-items: center; gap: 8px; margin: 4px 8px 16px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.compose-btn:hover { background: var(--brand-dark); }
.compose-btn .plus { font-size: 18px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-radius: 0 24px 24px 0; margin-right: 8px; color: var(--text); cursor: pointer; font-size: 14px; }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--selected); color: var(--brand); font-weight: 600; }
.nav-item .icon { width: 18px; text-align: center; }
.nav-item .count { margin-left: auto; font-size: 12px; color: var(--text-muted); }
.nav-item.active .count { color: var(--brand); }
.nav-divider { height: 1px; background: var(--border); margin: 10px 12px; }

.content { background: var(--surface); overflow: hidden; display: flex; flex-direction: column; }

/* ---- Message list ---- */
.list-toolbar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.list-toolbar .refresh, .list-toolbar .toolbar-btn { padding: 6px 12px; border-radius: 6px; font-size: 13px; color: var(--text-muted); }
.list-toolbar .refresh:hover, .list-toolbar .toolbar-btn:hover { background: var(--hover); color: var(--text); }
.list-toolbar .spacer { flex: 1; }
.list-toolbar .info { font-size: 12px; color: var(--text-muted); }
.message-list { overflow-y: auto; flex: 1; }
.msg-row { display: grid; grid-template-columns: 220px 1fr 100px; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: center; background: var(--read-bg); }
.msg-row.unread { background: var(--unread-bg); font-weight: 600; }
.msg-row:hover { background: var(--hover); box-shadow: inset 1px 0 0 var(--brand); }
.msg-row .from { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-row .subject { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-row .subject .preview { font-weight: 400; color: var(--text-muted); }
.msg-row .date { font-size: 12px; color: var(--text-muted); text-align: right; }
.empty { padding: 60px 16px; text-align: center; color: var(--text-muted); }

/* ---- Message reader ---- */
.reader { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.reader-toolbar { display: flex; align-items: center; gap: 6px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.reader-toolbar .toolbar-btn { padding: 6px 12px; border-radius: 6px; color: var(--text-muted); font-size: 13px; }
.reader-toolbar .toolbar-btn:hover { background: var(--hover); color: var(--text); }
.reader-toolbar .toolbar-btn.danger:hover { color: var(--danger); }
.reader-toolbar .back { font-size: 18px; }
.reader-header { padding: 20px 24px 10px; border-bottom: 1px solid var(--border); }
.reader-subject { font-size: 22px; margin: 0 0 8px; }
.reader-meta { display: flex; gap: 12px; align-items: center; color: var(--text-muted); font-size: 13px; }
.reader-meta .avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: white; display: grid; place-items: center; font-weight: 700; }
.reader-meta .from-line { color: var(--text); font-weight: 600; }
.reader-meta .from-line .addr { color: var(--text-muted); font-weight: 400; margin-left: 6px; }
.reader-meta .right { margin-left: auto; }
.reader-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.reader-body iframe { width: 100%; border: 0; min-height: 400px; }
.reader-body pre { white-space: pre-wrap; font-family: inherit; margin: 0; }
.attachments { padding: 12px 24px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 8px; }
.attachment { padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.attachment a { color: var(--brand); margin-left: 8px; }

/* ---- Compose ---- */
.compose-modal { position: fixed; right: 24px; bottom: 0; width: 540px; max-height: 80vh; background: var(--surface); box-shadow: 0 10px 40px rgba(0,0,0,.2); border-radius: 8px 8px 0 0; display: flex; flex-direction: column; z-index: 100; }
.compose-header { padding: 10px 16px; background: #424242; color: white; border-radius: 8px 8px 0 0; display: flex; align-items: center; justify-content: space-between; }
.compose-header span { font-weight: 600; font-size: 14px; }
.compose-header .close { color: white; padding: 4px 8px; }
.compose-body { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; overflow: auto; }
.compose-body label { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 8px; }
.compose-body label .field-name { width: 40px; }
.compose-body input.field { flex: 1; border-color: transparent; border-bottom: 1px solid var(--border); border-radius: 0; padding: 6px 0; }
.compose-body input.field:focus { border-color: transparent; border-bottom-color: var(--brand); }
.compose-body textarea { width: 100%; flex: 1; min-height: 200px; resize: vertical; border-color: transparent; }
.compose-footer { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: center; }
.compose-footer .send { background: var(--brand); color: white; padding: 8px 22px; border-radius: 6px; font-weight: 600; }
.compose-footer .send:hover { background: var(--brand-dark); }
.compose-footer .send:disabled { opacity: .6; cursor: not-allowed; }
.compose-footer .info { font-size: 12px; color: var(--text-muted); margin-left: auto; }

/* ---- Admin ---- */
.admin-wrap { padding: 20px 28px; overflow-y: auto; height: 100%; }
.admin-wrap h2 { margin: 0 0 16px; }
.admin-actions { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; }
.admin-actions button { background: var(--brand); color: white; padding: 8px 16px; border-radius: 6px; font-weight: 600; }
.admin-actions button:hover { background: var(--brand-dark); }
.accounts-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.accounts-table th { background: var(--bg); padding: 10px 12px; text-align: left; font-weight: 600; font-size: 13px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.accounts-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
.accounts-table tr:last-child td { border-bottom: 0; }
.accounts-table .badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.accounts-table .badge.admin { background: var(--brand-soft); color: var(--brand-dark); }
.accounts-table .badge.active { background: #d1fae5; color: #065f46; }
.accounts-table .badge.inactive { background: #fee2e2; color: #991b1b; }
.accounts-table .row-actions button { padding: 4px 8px; font-size: 12px; color: var(--text-muted); border-radius: 4px; }
.accounts-table .row-actions button:hover { background: var(--hover); color: var(--text); }
.accounts-table .row-actions button.danger:hover { color: var(--danger); }

.dialog-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 200; }
.dialog { background: var(--surface); border-radius: 10px; width: 420px; padding: 24px; }
.dialog h3 { margin: 0 0 16px; }
.dialog label { display: block; font-size: 12px; color: var(--text-muted); margin: 10px 0 4px; }
.dialog input, .dialog select { width: 100%; }
.dialog .row { display: flex; align-items: center; gap: 8px; }
.dialog .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.dialog button { padding: 8px 16px; border-radius: 6px; font-weight: 600; }
.dialog button.primary { background: var(--brand); color: white; }
.dialog button.primary:hover { background: var(--brand-dark); }
.dialog button.secondary { background: var(--hover); color: var(--text); }
.dialog .err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }
.dialog .info-block { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px; font-family: monospace; font-size: 12px; word-break: break-all; max-height: 240px; overflow-y: auto; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1f2937; color: white; padding: 10px 20px; border-radius: 24px; font-size: 13px; z-index: 1000; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

@media (max-width: 720px) {
  .main { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .msg-row { grid-template-columns: 1fr; gap: 4px; }
  .msg-row .date { text-align: left; }
  .compose-modal { right: 0; left: 0; width: auto; max-height: 100vh; height: 100vh; border-radius: 0; }
}
