:root { --ocean: #1d4c8c; --ocean-soft: #e7eef8; --ink: #1f2430; --muted: #6b7280; --line: #e5e7eb; --bg: #f6f5f2; --card: #fff; --ok: #2f7a4f; --bad: #b42318; --sel: #eef3fb; }
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.5 Inter, "Noto Sans Thai", system-ui, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--ocean); cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.btn { font: 500 13px Inter, sans-serif; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: #c7ccd4; }
.btn.primary { background: var(--ocean); color: #fff; border-color: var(--ocean); }
.btn.danger { color: var(--bad); }
.btn.link { border: 0; background: none; color: var(--ocean); padding: 4px 6px; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; font-size: 18px; width: 34px; height: 34px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: #eef0f3; }
input, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; width: 100%; color: var(--ink); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; text-align: left; }
label input { margin-top: 4px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: 100%; max-width: 360px; text-align: center; }
.login-card h1 { margin: 12px 0 0; font-size: 1.4rem; }
.login-card .btn.primary { width: 100%; justify-content: center; margin-top: 4px; }
#l-msg { margin-top: 10px; color: var(--bad); font-size: 13px; }

/* layout */
.app { display: grid; grid-template-columns: 220px minmax(300px, 400px) 1fr; height: 100vh; height: 100dvh; }
.side { background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px 14px; }
.brand b { display: block; font-size: 15px; }
.brand span { font-size: 11px; color: var(--muted); }
.compose-btn { margin: 0 4px 12px; justify-content: center; padding: 10px; }
#folders a { display: flex; justify-content: space-between; padding: 7px 12px; border-radius: 6px; color: var(--ink); text-decoration: none; font-weight: 500; }
#folders a:hover { background: #f3f4f6; }
#folders a.active { background: var(--ocean-soft); color: var(--ocean); }
.count { background: var(--ocean); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.count:empty { display: none; }
.side-foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }

.list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.bar { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); background: #fff; align-items: center; }
.bulk { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 10px; background: var(--ocean-soft); align-items: center; font-size: 12px; }
.threads { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.threads li { display: grid; grid-template-columns: 22px 1fr auto; gap: 4px 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; background: #fff; }
.threads li:hover { background: #fafbfc; }
.threads li.sel { background: var(--sel); }
.threads li.unread .who, .threads li.unread .subj { font-weight: 600; }
.threads li .chk { grid-row: span 3; margin-top: 2px; width: 16px; height: 16px; }
.threads .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.threads .when { font-size: 12px; color: var(--muted); white-space: nowrap; }
.threads .subj, .threads .snip { grid-column: 2 / 4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.threads .snip { color: var(--muted); font-size: 13px; }
.threads .star { color: #d4a017; }
.threads li.unread { box-shadow: inset 3px 0 0 var(--ocean); }
.threads .empty-row { display: block; text-align: center; color: var(--muted); padding: 40px 10px; cursor: default; }
.more { margin: 8px auto; }

.read { overflow-y: auto; background: #fff; min-width: 0; }
.empty { height: 100%; display: grid; place-items: center; color: var(--muted); }
.read-head { position: sticky; top: 0; background: #fff; z-index: 2; padding: 12px 20px; border-bottom: 1px solid var(--line); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.read-head h2 { flex-basis: 100%; margin: 6px 0 0; font-size: 1.2rem; font-weight: 600; }
.guest { margin: 14px 20px 0; padding: 10px 12px; background: var(--ocean-soft); border-radius: 8px; font-size: 13px; }
.guest a { font-weight: 600; }
.msg { border-bottom: 1px solid var(--line); padding: 14px 20px; }
.msg.collapsed { cursor: pointer; }
.msg.collapsed .msg-body, .msg.collapsed .atts, .msg.collapsed .msg-actions { display: none; }
.msg-meta { display: flex; justify-content: space-between; gap: 10px; }
.msg-meta .from b { font-weight: 600; }
.msg-meta .to { font-size: 12px; color: var(--muted); word-break: break-all; }
.msg-meta .when { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sent-tag { color: var(--ok); font-weight: 500; font-size: 12px; }
.msg .snip { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg:not(.collapsed) .snip { display: none; }
.msg-body { margin-top: 12px; }
.msg-body iframe { width: 100%; border: 0; min-height: 60px; display: block; }
.msg-body pre { white-space: pre-wrap; word-wrap: break-word; font: inherit; margin: 0; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.att { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; text-decoration: none; color: var(--ink); display: flex; gap: 6px; align-items: center; max-width: 260px; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att:hover { border-color: var(--ocean); }
.msg-actions { margin-top: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.fwd-warn { font-size: 12px; color: #b45309; margin-top: 6px; }

/* compose */
.compose { position: fixed; right: 24px; bottom: 0; width: min(620px, 100vw); z-index: 20; }
.compose form { background: #fff; border: 1px solid var(--line); border-radius: 10px 10px 0 0; box-shadow: 0 8px 30px rgba(0,0,0,.18); display: flex; flex-direction: column; max-height: 88vh; }
.compose header { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 14px; background: var(--ink); color: #fff; border-radius: 10px 10px 0 0; cursor: pointer; }
.compose header .icon-btn { color: #fff; width: 28px; height: 28px; font-size: 15px; }
.compose header .icon-btn:hover { background: rgba(255,255,255,.15); }
.compose.min .cmp-body, .compose.min footer { display: none; }
.cmp-body { padding: 4px 14px; overflow-y: auto; position: relative; }
.field { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.field > span { color: var(--muted); font-size: 13px; width: 56px; flex-shrink: 0; }
.field > b { font-weight: 500; font-size: 13px; padding: 8px 0; }
.field input { border: 0; padding: 8px 0; border-radius: 0; }
.field input:focus { outline: none; }
#cmp-text { border: 0; min-height: 220px; resize: vertical; padding: 10px 0; }
#cmp-text:focus { outline: none; }
.suggest { position: absolute; left: 76px; right: 14px; z-index: 5; list-style: none; margin: 0; padding: 4px 0; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.1); }
.suggest li { padding: 6px 10px; cursor: pointer; font-size: 13px; }
.suggest li:hover, .suggest li.on { background: var(--sel); }
.cmp-atts { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 8px; }
.cmp-atts .att button { border: 0; background: none; cursor: pointer; color: var(--muted); }
.quoted { font-size: 12px; color: var(--muted); padding-bottom: 10px; }
.quoted div { border-left: 2px solid var(--line); padding-left: 10px; margin-top: 6px; white-space: pre-wrap; max-height: 200px; overflow-y: auto; }
.compose footer { display: flex; gap: 8px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); }
.compose footer #cmp-discard { margin-left: auto; }
.attach-btn { cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 50; font-size: 13px; }
.toast.err { background: var(--bad); }
.only-mobile { display: none; }

@media (max-width: 1000px) {
  .app { grid-template-columns: 190px 1fr; }
  .app .read { position: fixed; inset: 0; z-index: 10; display: none; }
  .app.reading .read { display: block; }
}
@media (max-width: 700px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-block; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 15; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.15); }
  .app.menu .side { transform: none; }
  .compose { right: 0; left: 0; width: 100%; }
  .compose form { max-height: 100dvh; height: 100dvh; border-radius: 0; }
  .compose header { border-radius: 0; }
  .read-head, .msg { padding-left: 14px; padding-right: 14px; }
  .guest { margin-left: 14px; margin-right: 14px; }
}

#mail-lang { width: auto; padding: 4px 8px; font-size: 12px; margin-bottom: 4px; }
