/*
  60 : 30 : 10 — light blue
  60%  dominant  --bg      page background, near-white blue
  30%  secondary --soft    composer panel, thumbnails, chips, ghost buttons
  10%  accent    --accent  primary actions, links, progress, selection
*/
:root {
  --bg: #f3f8ff;
  --surface: #ffffff;
  --soft: #dceafe;
  --soft-strong: #c8ddfd;
  --soft-ink: #2a5bb8;
  --accent: #2f6bf0;
  --accent-hover: #2358d0;
  --accent-ink: #ffffff;
  --ink: #142b52;
  --muted: #5f7799;
  --line: #d9e6f8;
  --danger: #d9434b;
  --danger-soft: #fde8ea;
  --warn-bg: #fff4dc;
  --warn-ink: #8a5a00;
  --shadow-sm: 0 1px 2px rgba(20, 43, 82, .05);
  --shadow: 0 8px 24px -10px rgba(47, 107, 240, .25);
  --r-sm: 12px;
  --r: 18px;
  --r-lg: 26px;
  --font: "IBM Plex Sans Thai", system-ui, -apple-system, "Sukhumvit Set", "Leelawadee UI", "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(900px 420px at 100% -10%, #e3efff 0%, transparent 60%),
    radial-gradient(700px 360px at -10% 0%, #eaf3ff 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 14px; }

/* icons */
.ic {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.ic-xs { width: 14px; height: 14px; }
.ic-lg { width: 26px; height: 26px; }
.ic-xl { width: 44px; height: 44px; }
#i-more circle, #i-play path { fill: currentColor; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px; border-radius: 999px; border: 0;
  font-weight: 600; font-size: 15px; white-space: nowrap;
  transition: background .15s, color .15s, transform .1s, box-shadow .15s;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: var(--soft); color: var(--soft-ink); }
.btn-ghost:hover { background: var(--soft-strong); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; height: 50px; font-size: 16px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 999px; display: grid; place-items: center;
  background: var(--surface); color: var(--soft-ink); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}

/* form fields */
.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; font-weight: 500; color: var(--muted); }
.field input {
  height: 48px; padding: 0 14px; border-radius: var(--r-sm);
  border: 1.5px solid var(--line); background: var(--bg); font-size: 16px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.field input:focus, .text-form textarea:focus {
  outline: none; border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 4px rgba(47, 107, 240, .14);
}
.check-row { display: flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; }
.check-row input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(400px, 100%); background: var(--surface); border-radius: var(--r-lg);
  box-shadow: 0 24px 60px -24px rgba(20, 43, 82, .25); overflow: hidden;
}
.login-hero {
  background: linear-gradient(160deg, var(--soft) 0%, #eaf2ff 100%);
  padding: 32px 24px 26px; text-align: center;
}
.login-hero img { filter: drop-shadow(0 8px 16px rgba(47, 107, 240, .3)); }
.login-hero h1 { margin: 12px 0 2px; font-size: 28px; font-weight: 700; letter-spacing: -.01em; }
.login-hero p { margin: 0; color: var(--muted); font-size: 15px; }
.login-fields { padding: 24px; display: grid; gap: 14px; }
.login-device {
  margin: 0; display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 13px; color: var(--muted);
  background: var(--bg); border-radius: 999px; padding: 6px 12px; justify-self: center;
}
.login-device b { color: var(--soft-ink); font-weight: 600; }

/* ---------- app shell ---------- */
#app-view { max-width: 720px; margin: 0 auto; padding: 0 16px 64px; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0 12px;
  background: linear-gradient(var(--bg) 75%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 10px; }
.brand-name { font-weight: 700; font-size: 20px; line-height: 1.1; }
.brand-sub {
  display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.usage {
  margin-left: auto; display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  font-size: 12px; color: var(--muted); white-space: nowrap; box-shadow: var(--shadow-sm);
}
.usage-bar { width: 64px; height: 6px; border-radius: 99px; background: var(--soft); overflow: hidden; }
#usage-fill { height: 100%; width: 0; min-width: 3px; background: var(--accent); border-radius: 99px; transition: width .4s; }
.usage.warn #usage-fill { background: #e39a12; }
.usage.full #usage-fill { background: var(--danger); }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary { background: var(--soft); border-color: var(--soft-strong); }
.menu-pop {
  position: absolute; right: 0; top: 50px; min-width: 240px; z-index: 10;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 6px; display: grid; box-shadow: 0 18px 40px -12px rgba(20, 43, 82, .22);
}
.menu-pop button {
  display: flex; align-items: center; gap: 10px; text-align: left;
  border: 0; background: none; padding: 11px 12px; border-radius: var(--r-sm); font-size: 15px;
}
.menu-pop button:hover { background: var(--bg); }
.menu-pop button .ic { color: var(--soft-ink); }
.menu-pop .danger, .menu-pop .danger .ic { color: var(--danger); }
.menu-pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }

.banner {
  background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--r-sm);
  padding: 10px 14px; margin-bottom: 12px; font-size: 14px; font-weight: 500;
}

/* ---------- composer (30% secondary panel) ---------- */
.composer {
  background: var(--soft); border-radius: var(--r-lg); padding: 16px;
  display: grid; gap: 12px; margin: 4px 0 28px;
}
.drop-zone {
  display: flex; align-items: center; gap: 16px;
  padding: 18px; border-radius: var(--r);
  background: rgba(255, 255, 255, .7); border: 2px dashed #a9c8fa;
  cursor: pointer; transition: border-color .15s, background .15s, transform .1s;
}
.drop-zone:hover { border-color: var(--accent); background: var(--surface); }
.drop-zone:active { transform: scale(.995); }
.drop-badge {
  width: 52px; height: 52px; border-radius: 16px; flex: none;
  display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow);
}
.drop-text { display: grid; font-size: 16px; }
.drop-text b { color: var(--accent); }
.drop-hint { font-size: 13px; color: var(--muted); }

.text-form {
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--surface); border-radius: var(--r); padding: 6px 6px 6px 4px;
}
.text-form textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 200px; field-sizing: content;
  padding: 10px 12px; border: 1.5px solid transparent; border-radius: var(--r-sm); background: transparent; font-size: 16px;
}
.text-form textarea:focus { box-shadow: none; border-color: transparent; }
.send-btn { height: 44px; padding: 0 18px; }

.uploads { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.uploads:empty { display: none; }
.uploads li {
  background: var(--surface); border-radius: var(--r-sm); padding: 10px 14px;
  font-size: 14px; display: grid; gap: 8px;
}
.uploads .row { display: flex; justify-content: space-between; gap: 10px; }
.uploads .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.uploads progress { width: 100%; height: 6px; border: 0; border-radius: 99px; overflow: hidden; appearance: none; background: var(--soft); }
.uploads progress::-webkit-progress-bar { background: var(--soft); }
.uploads progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
.uploads progress::-moz-progress-bar { background: var(--accent); }
.uploads li.failed { color: var(--danger); background: var(--danger-soft); cursor: pointer; }

/* ---------- list ---------- */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.list-head h2 { font-size: 18px; margin: 0; display: flex; align-items: center; gap: 8px; }
.chip {
  font-size: 12px; font-weight: 600; color: var(--soft-ink); background: var(--soft);
  padding: 2px 10px; border-radius: 999px;
}
.chip:empty { display: none; }
.select-tools { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.select-tools .btn { height: 36px; padding: 0 14px; font-size: 14px; }

.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  background: var(--surface); border: 1.5px solid transparent; border-radius: var(--r);
  padding: 12px; box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.item:hover { box-shadow: 0 6px 18px -10px rgba(20, 43, 82, .22); }
.item .check { display: none; width: 22px; height: 22px; accent-color: var(--accent); margin: 0 2px; }
.selecting .item .check { display: block; }
.selecting .item { grid-template-columns: auto auto 1fr auto; cursor: pointer; }
.item.selected { border-color: var(--accent); background: #f6f9ff; }

.thumb {
  position: relative; width: 56px; height: 56px; border-radius: 14px; border: 0; padding: 0;
  background: var(--soft); color: var(--soft-ink);
  display: grid; place-items: center; overflow: hidden;
}
button.thumb { cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ext {
  position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%);
  font-size: 9px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
}
.thumb .ic { margin-top: -8px; }
.thumb.text-thumb .ic { margin-top: 0; }
.thumb.media::after {
  content: ""; position: absolute; inset: 0; background: rgba(20, 43, 82, .0);
}
.meta { min-width: 0; }
.meta .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.text-body {
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
  max-height: 9.5em; overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; font-size: 15px; line-height: 1.55;
  padding: 3px 0; /* Thai glyphs overflow the line box by ~1px; padding absorbs it so no scrollbar appears */
}
.text-body a { color: var(--accent); font-weight: 500; text-decoration-thickness: 1px; text-underline-offset: 2px; }

.actions { display: flex; gap: 6px; }
.actions a, .actions button {
  width: 40px; height: 40px; border-radius: 999px; border: 0;
  display: grid; place-items: center; text-decoration: none;
  background: var(--soft); color: var(--soft-ink);
  transition: background .15s, color .15s;
}
.actions a:hover, .actions button:hover { background: var(--accent); color: var(--accent-ink); }
.actions .del { background: transparent; color: var(--muted); }
.actions .del:hover { background: var(--danger-soft); color: var(--danger); }
.actions .copied { background: var(--accent); color: var(--accent-ink); }
.selecting .actions { display: none; }

.empty { text-align: center; padding: 48px 0; color: var(--muted); }
.empty-badge {
  width: 64px; height: 64px; border-radius: 20px; margin: 0 auto 8px;
  display: grid; place-items: center; background: var(--soft); color: var(--soft-ink);
}

/* ---------- overlays ---------- */
.drag-overlay {
  position: fixed; inset: 12px; z-index: 20; display: grid; place-items: center; text-align: center;
  border: 3px dashed var(--accent); border-radius: var(--r-lg);
  background: rgba(220, 234, 254, .92); color: var(--accent);
  font-size: 22px; font-weight: 700; pointer-events: none;
}
.drag-overlay p { margin: 6px 0 0; }

dialog#viewer {
  border: 0; padding: 0; background: #0d1a30; max-width: 96vw; max-height: 92dvh; border-radius: var(--r);
}
dialog#viewer::backdrop { background: rgba(13, 26, 48, .78); }
.viewer-body video, .viewer-body img, .viewer-body audio { display: block; max-width: 96vw; max-height: 92dvh; }
.viewer-close {
  position: absolute; top: 10px; right: 10px; background: rgba(255, 255, 255, .9); color: var(--ink); border: 0;
  width: 36px; height: 36px; border-radius: 50%; padding: 0; font-size: 14px;
}

dialog.sheet { border: 0; padding: 0; background: transparent; width: min(420px, calc(100vw - 24px)); }
dialog.sheet::backdrop { background: rgba(20, 43, 82, .35); backdrop-filter: blur(2px); }
.sheet-card {
  background: var(--surface); border-radius: var(--r-lg); padding: 24px;
  display: grid; gap: 14px; box-shadow: 0 24px 60px -20px rgba(20, 43, 82, .35);
}
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-badge {
  width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center;
  background: var(--soft); color: var(--soft-ink);
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 999px; font-size: 14px; font-weight: 500;
  z-index: 30; max-width: 90vw; box-shadow: 0 12px 30px -10px rgba(20, 43, 82, .5);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- small screens ---------- */
@media (max-width: 520px) {
  #app-view { padding: 0 12px 56px; }
  .usage { padding: 6px 10px; }
  .usage-bar { width: 40px; }
  .composer { padding: 12px; border-radius: 22px; }
  .drop-zone { padding: 14px; gap: 12px; }
  .drop-badge { width: 46px; height: 46px; border-radius: 14px; }
  .send-btn span { display: none; }
  .send-btn { width: 44px; padding: 0; }
  .item { gap: 12px; padding: 10px; }
  .thumb { width: 50px; height: 50px; }
  .actions a, .actions button { width: 36px; height: 36px; }
}
@media (max-width: 380px) {
  .usage span { display: none; }
}
