:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #1f1f1f; --ink-2: #4a4a4a; --muted: #8a8780;
  --line: #e7e4dd; --hover: #f1efe9; --sel: #fbf6ec; --accent: #1f1f1f; --gold: #b08d57;
  --danger: #b4372f; --ok: #2f7a4b;
  --leasing: #2563a8; --management: #2f7a4b; --development: #7a4bb0; --other: #8a8780;
  --radius: 10px; --shadow: 0 8px 30px rgba(0,0,0,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141414; --panel: #1c1c1c; --ink: #f1efe9; --ink-2: #c9c6be; --muted: #8e8b84;
    --line: #2c2b29; --hover: #242322; --sel: #2a2620; --accent: #f1efe9; --gold: #d9b26f;
    --leasing: #6aa5e8; --management: #5fbf86; --development: #b38ae6; --other: #8e8b84;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--panel); border-color: var(--accent); }
.btn.primary:hover { opacity: .88; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: .5; cursor: progress; }
.icon-btn { border: 0; background: transparent; font-size: 18px; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--hover); }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login-card h1 { margin: 4px 0 6px; font-size: 24px; font-weight: 600; }
.brand-mark { font-family: Georgia, "Times New Roman", serif; letter-spacing: .04em; color: var(--gold); font-size: 13px; text-transform: uppercase; }
.field { display: block; margin-top: 14px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.field input:focus, .field textarea:focus, .field select:focus, .search input:focus { outline: 2px solid var(--gold); outline-offset: -1px; }

/* layout */
.app { height: 100%; display: grid; grid-template-columns: 220px 360px 1fr; grid-template-rows: 56px 1fr; grid-template-areas: "top top top" "side list reader"; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; flex-direction: column; line-height: 1.1; min-width: 150px; }
.brand-sub { font-weight: 600; font-size: 15px; }
.search { flex: 1; max-width: 520px; }
.search input { width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.me { margin-left: auto; display: flex; align-items: center; gap: 6px; color: var(--ink-2); }

.sidebar { grid-area: side; background: var(--panel); border-right: 1px solid var(--line); padding: 14px 10px; overflow: hidden auto; }
.f-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.side-group + .side-group { margin-top: 18px; }
.side-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 0 8px 6px; }
.folder { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px; border-radius: 8px; cursor: pointer; }
.folder:hover { background: var(--hover); }
.folder.on { background: var(--sel); font-weight: 600; }
.folder .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--other); flex: none; }
.folder .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.folder .count.hot { color: var(--panel); background: var(--gold); border-radius: 10px; padding: 0 7px; font-weight: 600; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 0 4px; }
.seg button { border: 1px solid var(--line); background: transparent; padding: 6px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--accent); color: var(--panel); border-color: var(--accent); }
.side-foot { font-size: 12px; padding: 18px 8px 0; }

.list { grid-area: list; border-right: 1px solid var(--line); overflow: auto; background: var(--panel); }
.list-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); font-weight: 600; z-index: 1; }
#threads { list-style: none; margin: 0; padding: 0; }
.trow { padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.trow:hover { background: var(--hover); }
.trow.on { background: var(--sel); box-shadow: inset 3px 0 0 var(--gold); }
.trow .who { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trow.unread .who, .trow.unread .subj { font-weight: 700; }
.trow .when { font-size: 12px; color: var(--muted); }
.trow .subj { grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trow .snip { grid-column: 1 / -1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trow .meta { grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; margin-top: 2px; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 10px; border: 1px solid currentColor; line-height: 1.5; }
.b-leasing { color: var(--leasing); } .b-management { color: var(--management); } .b-development { color: var(--development); } .b-other { color: var(--other); }
.udot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); display: inline-block; }
.replied { font-size: 11px; color: var(--muted); }
.empty { text-align: center; padding: 40px 0; }

.reader { grid-area: reader; overflow: auto; background: var(--bg); }
.reader-empty { height: 100%; display: grid; place-items: center; }
.r-head { position: sticky; top: 0; z-index: 2; background: var(--panel); border-bottom: 1px solid var(--line); padding: 12px 20px; display: flex; gap: 10px; align-items: flex-start; }
.r-head h2 { margin: 0; font-size: 18px; font-weight: 600; flex: 1; overflow-wrap: anywhere; }
.r-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.r-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.msgs { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; max-width: 980px; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.msg.out { border-left: 3px solid var(--gold); }
.m-head { display: flex; gap: 10px; padding: 12px 14px; cursor: pointer; align-items: flex-start; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--hover); display: grid; place-items: center; font-weight: 600; flex: none; color: var(--ink-2); }
.msg.out .avatar { background: var(--accent); color: var(--panel); }
.m-who { flex: 1; min-width: 0; }
.m-who .name { font-weight: 600; }
.m-who .addr, .m-who .to { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.m-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.m-body { padding: 0 14px 14px 58px; }
.msg.collapsed .m-body { display: none; }
.msg.collapsed .m-snip { display: block; }
.m-snip { display: none; color: var(--muted); padding: 0 14px 12px 58px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font: inherit; }
.quote-toggle { border: 1px solid var(--line); background: var(--hover); border-radius: 6px; padding: 0 8px; cursor: pointer; font-size: 12px; margin: 6px 0; }
.m-quote { white-space: pre-wrap; color: var(--muted); border-left: 3px solid var(--line); padding-left: 10px; margin: 6px 0 0; font: inherit; overflow-wrap: anywhere; }
.m-frame { width: 100%; border: 0; min-height: 60px; background: #fff; border-radius: 6px; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.att { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; text-decoration: none; color: var(--ink); font-size: 13px; max-width: 280px; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att small { color: var(--muted); }
.m-tools { margin-top: 10px; font-size: 12px; }
.m-tools a { color: var(--muted); }
.warn { color: var(--danger); font-size: 12px; }

/* composer */
.composer { margin: 4px 20px 24px; max-width: 980px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.c-row { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }
.c-row label { color: var(--muted); font-size: 13px; }
.c-row input, .c-row select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); width: 100%; }
.composer textarea { width: 100%; min-height: 140px; resize: vertical; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.c-sig { color: var(--muted); font-size: 12px; margin: 6px 0 0; white-space: pre-line; }
.c-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.c-file { font-size: 12px; border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; }
.c-file button { border: 0; background: none; cursor: pointer; color: var(--muted); }
.c-actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.c-actions .spacer { flex: 1; }
.attach-label { cursor: pointer; color: var(--ink-2); font-size: 13px; }
.history { color: var(--muted); font-size: 12px; padding: 0 20px 8px; max-width: 980px; }

.dlg { border: 0; border-radius: 14px; padding: 0; width: min(720px, calc(100vw - 32px)); background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(0,0,0,.35); }
.dlg .composer { margin: 0; box-shadow: none; border: 0; }
.dlg h3 { margin: 0 0 12px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px); background: var(--accent); color: var(--panel); padding: 10px 16px; border-radius: 10px; transition: transform .25s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--danger); color: #fff; }

.only-mobile { display: none; }

/* phones / small tablets: one pane at a time */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 56px 1fr; grid-template-areas: "top" "list"; }
  .only-mobile { display: inline-block; }
  .brand { min-width: 0; } .brand-mark { display: none; }
  .me span { display: none; }
  .search { min-width: 0; }
  #new-btn { padding: 8px 10px; }
  .sidebar { position: fixed; inset: 56px auto 0 0; width: 260px; z-index: 20; box-shadow: var(--shadow); transform: translateX(-105%); transition: transform .2s; }
  .app.side-open .sidebar { transform: none; }
  .reader { grid-area: list; display: none; }
  .app.reading .reader { display: block; }
  .app.reading .list { display: none; }
  .r-head { padding: 10px 12px; flex-wrap: wrap; }
  .msgs { padding: 12px; }
  .m-body { padding: 0 12px 12px; }
  .m-snip { padding: 0 12px 10px; }
  .composer { margin: 4px 12px 20px; }
}
