:root {
  --bg: #f6f7f5; --panel: #ffffff; --ink: #1c1f1a; --muted: #5f6660; --line: #e3e6e1; --hover: #eef2ec; --sel: #dcfce7;
  --brand: #15803d; --brand-ink: #ffffff; --unread: #0f172a; --warn: #b45309; --warn-bg: #fef3c7; --bad: #b91c1c; --chip: #eef1ec;
  --radius: 12px; font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1210; --panel: #171b18; --ink: #e8ece8; --muted: #9aa39b; --line: #2a302b; --hover: #202621; --sel: #173823; --unread: #ffffff; --warn-bg: #3a2a0c; --warn: #fbbf24; --chip: #232a24; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow-x: hidden; background: var(--bg); color: var(--ink); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 10px; }
button:hover { background: var(--hover); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.link { border: 0; background: none; color: var(--brand); padding: 2px 4px; }
button.icon { border: 0; background: none; width: 36px; height: 36px; border-radius: 50%; padding: 0; font-size: 18px; }
button.icon:hover { background: var(--hover); }
button.tiny { padding: 0 7px; font-size: 13px; border-radius: 6px; margin-left: 6px; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .err { color: var(--bad); min-height: 1.2em; } .grow { flex: 1; }
[hidden] { display: none !important; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: min(380px, 100%); display: grid; gap: 12px; }
.login-card label { display: grid; gap: 5px; font-weight: 600; font-size: 13px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand.big { font-size: 22px; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 16px; }

.app { display: grid; grid-template-columns: 236px 1fr; grid-template-rows: 60px 1fr; height: 100vh; height: 100dvh; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 0 14px; min-width: 0; border-bottom: 1px solid var(--line); background: var(--panel); }
.search { flex: 1; min-width: 0; display: flex; align-items: center; max-width: 760px; background: var(--hover); border-radius: 24px; padding: 2px 6px 2px 16px; }
.search input { flex: 1; border: 0; background: none; padding: 9px 4px; min-width: 0; }
.side { overflow: auto; padding: 12px 8px; border-right: 1px solid var(--line); }
.compose { width: 100%; padding: 12px; border-radius: 14px; background: var(--sel); border: 0; font-weight: 600; font-size: 15px; margin-bottom: 10px; }
.side h4 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 10px 6px; display: flex; align-items: center; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-radius: 0 18px 18px 0; color: inherit; text-decoration: none; margin-right: 6px; }
.nav a:hover { background: var(--hover); }
.nav a.on { background: var(--sel); font-weight: 700; }
.nav a .n { margin-left: auto; font-size: 12px; font-weight: 700; }
.nav .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.main { overflow: hidden; display: flex; flex-direction: column; background: var(--panel); min-width: 0; }
.cats { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; flex: none; }
.cats button { border: 0; border-radius: 0; background: none; padding: 12px 14px; border-bottom: 3px solid transparent; white-space: nowrap; color: var(--muted); }
.cats button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.cats .n { background: var(--brand); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; margin-left: 5px; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--line); min-height: 44px; flex: none; flex-wrap: wrap; }
.bulk { display: flex; gap: 4px; flex-wrap: wrap; }
.bulk button { padding: 4px 9px; font-size: 13px; }
.chk { display: grid; place-items: center; width: 28px; }
.list { overflow: auto; flex: 1; }
.row-t { display: grid; grid-template-columns: 28px 24px minmax(120px, 210px) 1fr auto; align-items: center; gap: 8px; padding: 9px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row-t:hover { background: var(--hover); box-shadow: inset 3px 0 0 var(--brand); }
.row-t.sel { background: var(--sel); }
.row-t.cur { box-shadow: inset 3px 0 0 var(--brand); }
.row-t.unread .who, .row-t.unread .subj { font-weight: 700; color: var(--unread); }
.row-t .who { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-t .line { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-t .snip { color: var(--muted); }
.row-t .when { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.row-t .star { border: 0; background: none; padding: 0; font-size: 17px; color: #c3c9c2; }
.row-t .star.on { color: #eab308; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--chip); margin-right: 5px; vertical-align: 1px; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.cat-orders { background: #dbeafe; color: #1e40af; } .tag.cat-shipping { background: #fef9c3; color: #854d0e; } .tag.cat-payments { background: #dcfce7; color: #166534; }
@media (prefers-color-scheme: dark) { .tag.cat-orders { background: #1e3a8a; color: #dbeafe; } .tag.cat-shipping { background: #713f12; color: #fef9c3; } .tag.cat-payments { background: #14532d; color: #dcfce7; } }
.empty { padding: 60px 20px; text-align: center; color: var(--muted); }

.reader { overflow: auto; flex: 1; padding: 10px 22px 40px; }
.reader h1 { font-size: 21px; font-weight: 500; margin: 12px 0 6px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.rtools { display: flex; gap: 6px; flex-wrap: wrap; padding: 6px 0 10px; border-bottom: 1px solid var(--line); position: sticky; top: -10px; background: var(--panel); z-index: 2; }
.msg { border-bottom: 1px solid var(--line); padding: 14px 0; }
.msg-head { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; }
.msg-head .meta { flex: 1; min-width: 0; }
.msg-head .meta b { margin-right: 6px; }
.msg.collapsed .msg-body { display: none; }
.msg.collapsed .msg-head .snip { display: block; }
.msg-head .snip { display: none; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-body { padding: 10px 0 0 50px; }
.msg-body iframe { width: 100%; border: 0; min-height: 120px; background: #fff; border-radius: 8px; }
.msg-body pre { white-space: pre-wrap; word-wrap: break-word; font: inherit; margin: 0; }
.safety { display: flex; gap: 8px; align-items: flex-start; background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 9px 12px; margin: 8px 0; }
.authline { font-size: 12px; color: var(--muted); margin-top: 2px; }
.authline .ok { color: #16a34a; } .authline .no { color: var(--bad); }
.imgs-off { font-size: 12.5px; background: var(--chip); padding: 6px 10px; border-radius: 8px; margin: 6px 0; display: flex; gap: 10px; align-items: center; }
.atts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.att { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; text-decoration: none; color: inherit; max-width: 260px; }
.att span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.found { display: grid; gap: 8px; margin: 12px 0; }
.found .fcard { border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 10px; padding: 9px 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.aibox { background: var(--chip); border-radius: 10px; padding: 10px 14px; margin: 10px 0; white-space: pre-wrap; }
.reply-bar { display: flex; gap: 8px; padding: 16px 0 0 50px; flex-wrap: wrap; }

.board { overflow: auto; flex: 1; padding: 14px 18px 40px; }
.board h2 { font-size: 18px; margin: 4px 0 4px; }
.board table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.board th, .board td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.board th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.board tr.click { cursor: pointer; } .board tr.click:hover { background: var(--hover); }
.stat { display: inline-flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; margin: 6px 8px 0 0; }
.stat b { font-size: 22px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 12px; background: var(--chip); }
.pill.delivered { background: #dcfce7; color: #166534; } .pill.problem { background: #fee2e2; color: #991b1b; } .pill.out { background: #dbeafe; color: #1e40af; }
.flag { color: var(--warn); font-weight: 600; font-size: 12.5px; }

.compose-box { position: fixed; right: 24px; bottom: 0; width: min(560px, 100vw); max-height: 88vh; background: var(--panel); border: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: 0 10px 40px rgba(0,0,0,.25); display: flex; flex-direction: column; z-index: 30; }
.compose-box.min .cb-body, .compose-box.min .cb-foot { display: none; }
.cb-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 14px; background: var(--hover); border-radius: 14px 14px 0 0; }
.cb-body { padding: 8px 14px; overflow: auto; display: grid; gap: 6px; position: relative; }
.cb-body .row { display: flex; align-items: center; gap: 8px; color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.cb-body .row input, .cb-body .row select { flex: 1; border: 0; background: none; padding: 6px 2px; }
.cb-body textarea { border: 0; resize: vertical; min-height: 200px; padding: 6px 2px; }
.cb-foot { display: flex; gap: 6px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.cb-foot .btn { border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; cursor: pointer; }
.suggest { position: absolute; left: 50px; right: 14px; top: 78px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); z-index: 5; }
.suggest button { display: block; width: 100%; text-align: left; border: 0; border-radius: 0; padding: 8px 12px; }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 40; padding: 16px; }
.sheet-card { background: var(--panel); border-radius: 16px; width: min(640px, 100%); max-height: 86vh; overflow: auto; padding: 4px 20px 20px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--panel); padding: 12px 0; }
.sheet-card label { display: grid; gap: 4px; font-weight: 600; font-size: 13px; margin: 10px 0; }
.sheet-card .list-x > div { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kbd { font-family: ui-monospace, monospace; background: var(--chip); border-radius: 5px; padding: 1px 6px; font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; display: flex; gap: 14px; align-items: center; box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.toast button { background: none; border: 0; color: #86efac; font-weight: 700; padding: 0; }

.only-mobile { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; top: 60px; left: 0; bottom: 0; width: 260px; background: var(--panel); z-index: 20; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.2); }
  .side.open { transform: none; }
  .only-mobile { display: inline-grid; } .hide-mobile { display: none; }
  .row-t { grid-template-columns: 24px 1fr auto; grid-template-areas: "c who when" "c line line"; row-gap: 2px; }
  .row-t .chk { grid-area: c; } .row-t .star { display: none; } .row-t .who { grid-area: who; } .row-t .line { grid-area: line; } .row-t .when { grid-area: when; }
  .msg-body, .reply-bar { padding-left: 0; }
  .reader { padding: 8px 12px 40px; }
  .compose-box { right: 0; left: 0; width: 100%; max-height: 100dvh; height: 100dvh; border-radius: 0; }
  .search input::placeholder { color: transparent; }
  .board td, .board th { padding: 7px 6px; font-size: 13px; }
}
