:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efeae2;
  --ink: #1d1b18;
  --ink-2: #4a453e;
  --muted: #6b645a;
  --line: #d8d0c4;
  --line-strong: #a89e8f;
  --accent: #1f5f5b;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe9;
  --warn: #9a4a00;
  --warn-soft: #fdf0dd;
  --danger: #a3261b;
  --danger-soft: #fbe4e1;
  --ok: #2f6b2a;
  --ok-soft: #e2f0dd;
  --focus: #e09a1f;
  --radius: 14px;
  --tap: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Tamil", "Tamil Sangam MN", "Nirmala UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 19px;
  line-height: 1.45;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 .75em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.25rem; color: var(--ink); text-decoration: none;
}
.brand-mark { color: var(--accent); display: inline-flex; }
.mainnav { display: flex; gap: 6px; margin-left: auto; }
.mainnav a {
  display: inline-flex; align-items: center; min-height: 48px; padding: 0 18px;
  border-radius: 999px; text-decoration: none; color: var(--ink-2); font-weight: 600;
}
.mainnav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.lang-toggle {
  display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 16px;
  border: 2px solid var(--accent); border-radius: 999px; background: var(--surface); color: var(--accent);
  font: inherit; font-weight: 700; cursor: pointer; touch-action: manipulation;
}
.lang-toggle:hover { background: var(--accent-soft); }
.lang-label { min-width: 3.5em; text-align: center; }
/* Tamil words run longer: let nav and buttons wrap instead of overflowing */
html[lang="ta"] body { font-size: 18px; }
html[lang="ta"] .mainnav a { padding: 0 12px; }
html[lang="ta"] .tb-btn { font-size: .78rem; line-height: 1.15; text-align: center; }
@media (max-width: 760px) {
  .mainnav { margin-left: 0; order: 3; width: 100%; flex-wrap: wrap; gap: 4px; }
  .mainnav a { padding: 0 10px; font-size: .92rem; }
  .lang-toggle { margin-left: auto; }
}

main { max-width: 1100px; margin: 0 auto; padding: 24px 20px 120px; outline: none; }
main.wide { max-width: none; padding: 0 0 160px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: var(--tap); padding: 0 22px;
  border: 2px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.btn:hover { border-color: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #174b48; }
.btn.danger { color: var(--danger); border-color: #d8a39d; }
.btn.small { min-height: 44px; padding: 0 14px; font-size: .95rem; }
.btn.block { width: 100%; }
.btn svg { flex: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

.big-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 28px; }
.big-action {
  display: flex; align-items: center; gap: 16px; min-height: 96px; padding: 18px 20px;
  border-radius: 18px; border: 2px solid var(--line); background: var(--surface);
  text-decoration: none; color: var(--ink); font-size: 1.15rem; font-weight: 700;
}
.big-action:hover { border-color: var(--accent); }
.big-action .ico {
  flex: none; width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent);
}

/* ---------- cards / lists ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 20px; margin-bottom: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--line); }
.row-link {
  display: flex; align-items: center; gap: 14px; min-height: 68px; padding: 10px 6px;
  color: var(--ink); text-decoration: none;
}
.row-link:hover { background: var(--surface-2); border-radius: 10px; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 700; }
.row-sub { color: var(--muted); font-size: .95rem; }
.row-end { text-align: right; color: var(--muted); font-size: .95rem; }
.chev { color: var(--line-strong); flex: none; }
.empty { color: var(--muted); padding: 14px 4px; }

.thumb {
  flex: none; width: 54px; height: 70px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface-2); display: grid; place-items: center; color: var(--muted);
  font-size: .72rem; font-weight: 700; overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }

.pill {
  display: inline-block; padding: 3px 12px; border-radius: 999px; font-size: .85rem; font-weight: 700;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.pill.New { background: #e5ecf7; color: #234a85; }
.pill.InProgress { background: var(--warn-soft); color: var(--warn); }
.pill.Ready { background: var(--ok-soft); color: var(--ok); }
.pill.Delivered { background: var(--surface-2); color: var(--muted); }
.pill.Cancelled { background: var(--danger-soft); color: var(--danger); }
.pill.src { background: var(--accent-soft); color: var(--accent); }

.crumbs { margin-bottom: 14px; font-size: .95rem; }
.crumbs a { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; text-decoration: none; font-weight: 600; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.meta-line { color: var(--muted); margin-top: 4px; }

/* ---------- forms ---------- */
.field { margin-bottom: 20px; }
.field label, .field .label { display: block; font-weight: 700; margin-bottom: 6px; }
.field .hint { color: var(--muted); font-size: .92rem; margin: 4px 0 0; }
input[type="text"], input[type="tel"], input[type="search"], input[type="date"], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 14px;
  border: 2px solid var(--line-strong); border-radius: 12px; background: #fff; color: var(--ink);
  font: inherit;
}
textarea { min-height: 130px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 3px solid var(--accent-soft); }

.search {
  position: relative; margin-bottom: 18px;
}
.search input { padding-left: 52px; font-size: 1.1rem; min-height: 64px; border-radius: 16px; }
.search svg { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); }

.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented button {
  min-height: 52px; padding: 0 18px; border-radius: 12px; border: 2px solid var(--line-strong);
  background: #fff; font: inherit; font-weight: 600; cursor: pointer; color: var(--ink);
}
.segmented button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.check-row {
  display: flex; align-items: center; gap: 14px; min-height: 64px; padding: 8px 12px;
  border: 2px solid var(--line); border-radius: 12px; margin-bottom: 8px; cursor: pointer; background: #fff;
}
.check-row input { width: 28px; height: 28px; flex: none; accent-color: var(--accent); }
.check-row:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

.notice { padding: 14px 16px; border-radius: 12px; margin-bottom: 18px; border: 2px solid; }
.notice.warn { background: var(--warn-soft); border-color: #e7c08d; color: #5b3000; }
.notice.info { background: var(--accent-soft); border-color: #a9cdc9; color: #123c39; }
.notice h3 { margin-bottom: 6px; }

/* ---------- choice tiles ---------- */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.choice {
  display: flex; flex-direction: column; gap: 10px; text-align: left; padding: 24px;
  border-radius: 18px; border: 2px solid var(--line); background: var(--surface);
  font: inherit; color: var(--ink); cursor: pointer; text-decoration: none; min-height: 170px;
}
.choice:hover, .choice[aria-pressed="true"] { border-color: var(--accent); background: #fbfdfc; }
.choice .ico { width: 56px; height: 56px; border-radius: 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.choice strong { font-size: 1.2rem; }
.choice span { color: var(--muted); }

/* ---------- file preview ---------- */
.preview-frame { width: 100%; height: 72vh; min-height: 480px; border: 1px solid var(--line); border-radius: 12px; background: #e9e5df; }
.preview-img { display: block; max-width: 100%; margin: 0 auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* ---------- ink notes (read-only) ---------- */
.ink-view { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: #fffdf8; display: block; }

/* ---------- editor ---------- */
.editor-top {
  position: relative; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.editor-top .title { font-weight: 700; flex: 1; min-width: 200px; }
.editor-top .title small { display: block; font-weight: 500; color: var(--muted); font-size: .9rem; }
.sheet-scroll { padding: 20px 12px 40px; }
.sheet-wrap {
  position: relative; margin: 0 auto; max-width: 900px;
  box-shadow: 0 2px 0 var(--line), 0 10px 30px rgba(40, 30, 10, .12); background: #fff;
}
.sheet-wrap canvas { display: block; width: 100%; height: auto; }
.sheet-wrap canvas.ink { position: absolute; inset: 0; }
.sheet-wrap.mode-brush canvas.ink { cursor: crosshair; }
.sheet-wrap.mode-erase canvas.ink { cursor: cell; }
.sheet-wrap.mode-type canvas.ink { cursor: text; }

.type-box {
  position: absolute; z-index: 5; margin: 0; padding: 0 .3em;
  border: 3px solid var(--accent); border-radius: 6px; background: rgba(255, 255, 255, .96);
  font-family: var(--font); color: #0d2f80; min-height: 0;
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.type-box:focus { outline: none; }

.toolbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 40;
  display: flex; flex-direction: column; gap: 8px;
  width: min(760px, calc(100vw - 24px));
  padding: 10px; border-radius: 22px;
  background: #23211e; color: #fff;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
.toolbar.at-top { bottom: auto; top: 140px; }
.tb-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: stretch; }
.tb-group { display: flex; gap: 6px; padding: 4px; border-radius: 16px; background: #34312d; }
.tb-group[hidden] { display: none; }
.tb-btn {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 68px; min-height: 60px; padding: 6px 8px;
  border: 0; border-radius: 12px; background: transparent; color: #f2eee8;
  font: inherit; font-size: .86rem; font-weight: 700; cursor: pointer; touch-action: manipulation;
}
.tb-btn:hover { background: #45413b; }
.tb-btn[aria-pressed="true"] { background: #fff; color: #1d1b18; }
.tb-btn[disabled] { opacity: .35; cursor: not-allowed; }
.tb-btn.mode { min-width: 96px; font-size: 1rem; }
.tb-btn.mode[aria-pressed="true"] { background: var(--focus); color: #1d1b18; }
.tb-btn.save { background: var(--accent); color: #fff; min-width: 120px; margin-left: auto; }
.tb-btn.save:hover { background: #2a7a75; }
.tb-spacer { flex: 1; }
.tb-hint { font-size: .9rem; color: #d8d2c8; padding: 0 6px; align-self: center; }
.dot { display: inline-block; border-radius: 50%; background: currentColor; }

@media (max-width: 700px) {
  .tb-btn { min-width: 64px; font-size: .78rem; }
  .tb-btn.mode { min-width: 92px; }
  .editor-top { top: 0; position: relative; }
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(20, 16, 10, .55);
  display: grid; place-items: center; padding: 16px;
}
.modal {
  width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--surface); border-radius: 20px; padding: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal.wide { width: min(1000px, 100%); }
.modal h2 { margin-bottom: 12px; }
.modal .btn-row { margin-top: 18px; justify-content: flex-end; }

#toast {
  position: fixed; left: 50%; top: 84px; transform: translateX(-50%) translateY(-20px);
  z-index: 200; padding: 14px 22px; border-radius: 14px; background: #23211e; color: #fff;
  font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media print {
  .topbar, .toolbar, .btn, .crumbs { display: none !important; }
}
