/* ============================================================
   DocPro theme — design tokens ported from the Tailwind/shadcn
   theme into plain CSS variables (no build step). Light + dark.
   ============================================================ */

:root {
  --background: oklch(0.9754 0.0084 325.6414);
  --foreground: oklch(0.3257 0.1161 325.0372);
  --card: oklch(0.9754 0.0084 325.6414);
  --card-foreground: oklch(0.3257 0.1161 325.0372);
  --popover: oklch(1.0000 0 0);
  --popover-foreground: oklch(0.3257 0.1161 325.0372);
  --primary: oklch(0.5316 0.1409 355.1999);
  --primary-foreground: oklch(1.0000 0 0);
  --secondary: oklch(0.8696 0.0675 334.8991);
  --secondary-foreground: oklch(0.4448 0.1341 324.7991);
  --muted: oklch(0.9395 0.0260 331.5454);
  --muted-foreground: oklch(0.4924 0.1244 324.4523);
  --accent: oklch(0.8696 0.0675 334.8991);
  --accent-foreground: oklch(0.4448 0.1341 324.7991);
  --destructive: oklch(0.5248 0.1368 20.8317);
  --destructive-foreground: oklch(1.0000 0 0);
  --border: oklch(0.8568 0.0829 328.9110);
  --input: oklch(0.8517 0.0558 336.6002);
  --ring: oklch(0.5916 0.2180 0.5844);
  --sidebar: oklch(0.9360 0.0288 320.5788);
  --sidebar-foreground: oklch(0.4948 0.1909 354.5435);
  --sidebar-border: oklch(0.9383 0.0026 48.7178);
  --font-sans: 'Niramit', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans Thai', 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --radius: 0.5rem;
  --shadow-sm: 0 1px 3px 0px hsl(0 0% 0% / 0.10), 0 1px 2px -1px hsl(0 0% 0% / 0.10);
  --shadow-md: 0 1px 3px 0px hsl(0 0% 0% / 0.10), 0 2px 4px -1px hsl(0 0% 0% / 0.10);
  --shadow-lg: 0 1px 3px 0px hsl(0 0% 0% / 0.10), 0 4px 6px -1px hsl(0 0% 0% / 0.10);
}

.dark {
  --background: oklch(0.2409 0.0201 307.5346);
  --foreground: oklch(0.8398 0.0387 309.5391);
  --card: oklch(0.2803 0.0232 307.5413);
  --card-foreground: oklch(0.8456 0.0302 341.4597);
  --popover: oklch(0.1548 0.0132 338.9015);
  --popover-foreground: oklch(0.9647 0.0091 341.8035);
  --primary: oklch(0.4607 0.1853 4.0994);
  --primary-foreground: oklch(0.8560 0.0618 346.3684);
  --secondary: oklch(0.3137 0.0306 310.0610);
  --secondary-foreground: oklch(0.8483 0.0382 307.9613);
  --muted: oklch(0.2634 0.0219 309.4748);
  --muted-foreground: oklch(0.7940 0.0372 307.1032);
  --accent: oklch(0.3649 0.0508 308.4911);
  --accent-foreground: oklch(0.9647 0.0091 341.8035);
  --destructive: oklch(0.2258 0.0524 12.6119);
  --destructive-foreground: oklch(1.0000 0 0);
  --border: oklch(0.3286 0.0154 343.4461);
  --input: oklch(0.3387 0.0195 332.8347);
  --ring: oklch(0.5916 0.2180 0.5844);
  --sidebar: oklch(0.1893 0.0163 331.0475);
  --sidebar-foreground: oklch(0.8607 0.0293 343.6612);
  --sidebar-border: oklch(0 0 0);
}

/* ------------------------------ base ------------------------------ */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--background);
  color: var(--foreground);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------ app shell ------------------------------ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: var(--sidebar);
  color: var(--sidebar-foreground);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.side-brand { padding: 18px 20px; font-size: 20px; font-weight: 700; border-bottom: 1px solid var(--sidebar-border); }
.side-brand a { color: var(--sidebar-foreground); }
.side-brand a:hover { text-decoration: none; }

.side-nav { flex: 1; padding: 12px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--sidebar-foreground);
  opacity: 0.82;
  font-size: 15px;
  font-weight: 500;
}
.side-nav a .ic { width: 20px; text-align: center; font-size: 15px; }
.side-nav a:hover { opacity: 1; text-decoration: none; background: color-mix(in oklab, var(--sidebar-foreground) 10%, transparent); }
.side-nav a.active {
  opacity: 1;
  background: var(--primary);
  color: var(--primary-foreground);
}
.nav-section {
  padding: 16px 14px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  opacity: .55;
}
.side-nav .sub { display: flex; flex-direction: column; gap: 2px; }
.side-nav .sub a { padding-left: 38px; font-size: 14px; opacity: 0.72; }
.side-nav .sub a .ic { font-size: 13px; }

/* Collapsible groups */
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.side-nav .grp-head .lb { flex: 1; }
.side-nav .grp-head .caret { margin-left: auto; font-size: 11px; opacity: .7; transition: transform .15s ease; }
.nav-group:not(.collapsed) .grp-head .caret { transform: rotate(90deg); }
.nav-group.collapsed .sub { display: none; }

/* Collapsible section header (e.g. Tools / เครื่องมือ) */
.side-nav .section-head {
  display: flex; align-items: center; gap: 11px; width: 100%;
  margin-top: 6px;
  padding: 14px 12px 6px;
  background: transparent; border: 0; cursor: pointer;
  font-family: inherit; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--sidebar-foreground); opacity: .6;
}
.side-nav .section-head:hover { opacity: .9; }
.tools-body { display: flex; flex-direction: column; gap: 2px; }
.nav-group.collapsed > .tools-body { display: none; }

.side-foot { padding: 14px 16px; border-top: 1px solid var(--sidebar-border); }
.side-foot .who { font-size: 14px; font-weight: 600; }
.side-foot .who small { display: block; color: var(--muted-foreground); font-weight: 400; }
.side-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.side-actions .btn-link { color: var(--sidebar-foreground); opacity: 0.85; font-size: 14px; }
.lang-switch { display: flex; gap: 10px; margin-top: 10px; font-size: 13px; }
.lang-switch a { color: var(--sidebar-foreground); opacity: 0.6; }
.lang-switch a.on { opacity: 1; font-weight: 700; text-decoration: underline; }
.lang-switch a:hover { opacity: 1; text-decoration: none; }

.theme-toggle {
  background: transparent;
  border: 1px solid var(--sidebar-border);
  color: inherit;
  border-radius: var(--radius);
  width: 32px; height: 32px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}
.theme-toggle:hover { background: color-mix(in oklab, currentColor 12%, transparent); }

.content { flex: 1; min-width: 0; }

/* Mobile top bar + logged-out bar */
.mobilebar { display: none; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--sidebar); color: var(--sidebar-foreground); border-bottom: 1px solid var(--sidebar-border); }
.mobilebar .mtitle { font-weight: 700; }
.hamburger { background: transparent; border: 0; color: inherit; font-size: 22px; cursor: pointer; line-height: 1; }

.authbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 22px;
  background: var(--sidebar); color: var(--sidebar-foreground); border-bottom: 1px solid var(--sidebar-border); }
.authbar .brand { font-weight: 700; font-size: 18px; }

.scrim { display: none; }

/* ------------------------------ layout ------------------------------ */
.container { max-width: 980px; margin: 28px auto; padding: 0 18px; }
.container.auth { margin-top: 48px; }

/* ------------------------------ responsive ------------------------------ */
@media (max-width: 860px) {
  .mobilebar { display: flex; }
  .sidebar {
    position: fixed;
    z-index: 50;
    left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 40;
  }
  .container { margin: 18px auto; }
}

h1 { font-size: 24px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 18px 0 10px; }
.muted { color: var(--muted-foreground); }
.error { color: var(--destructive); font-weight: 600; }
.ok { color: var(--primary); font-weight: 600; }

.card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 22px;
  margin: 16px 0;
  box-shadow: var(--shadow-sm);
}
.card.narrow { max-width: 420px; }

/* ------------------------------ forms ------------------------------ */
label { display: block; margin: 12px 0; font-size: 14px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  background: var(--background);
  color: var(--foreground);
  border: 1px solid var(--input);
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 400;
}
input:focus, select:focus {
  outline: 2px solid var(--ring);
  outline-offset: 1px;
  border-color: var(--ring);
}
input[type=checkbox] { margin-right: 8px; }

/* ------------------------------ buttons ------------------------------ */
.btn {
  display: inline-block;
  background: var(--primary);
  color: var(--primary-foreground);
  border: 0;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.secondary { background: var(--secondary); color: var(--secondary-foreground); }
.btn.danger { background: var(--destructive); color: var(--destructive-foreground); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn-link { color: var(--sidebar-foreground); }

.actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }

/* ------------------------------ stats ------------------------------ */
.grid { display: flex; gap: 16px; flex-wrap: wrap; margin: 18px 0; }
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 18px 24px;
  min-width: 150px;
}
.stat .num { display: block; font-size: 30px; font-weight: 700; color: var(--primary); }
.stat .lbl { color: var(--muted-foreground); font-size: 13px; }

/* ------------------------------ tables ------------------------------ */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  overflow: hidden;
}
.table th, .table td { text-align: left; padding: 11px 13px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: top; }
.table th { background: var(--muted); color: var(--muted-foreground); font-weight: 600; }
.table .details { max-width: 280px; word-break: break-word; color: var(--muted-foreground); font-size: 12px; }

.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.tag {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-foreground);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
}

.copy { width: 100%; font-size: 12px; font-family: var(--font-mono); }
.filter { display: flex; align-items: flex-end; gap: 12px; margin: 14px 0; }

/* ------------------------------ document viewer ------------------------------ */
.viewer { margin: 16px 0; }
.viewer iframe {
  width: 100%;
  height: 78vh;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  background: #fff;
}
.viewer img {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
}

/* ------------------------------ AI suggestions ------------------------------ */
.ai-panel {
  background: var(--accent);
  color: var(--accent-foreground);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 16px 18px;
  margin: 16px 0;
}
.ai-panel .ai-head { font-weight: 700; margin-bottom: 8px; }
.ai-panel p { margin: 6px 0; }
.tag.small { font-size: 11px; }

/* ------------------------------ drag-drop menu manager ------------------------------ */
.menu-list { list-style: none; margin: 0; padding: 0; max-width: 620px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.menu-item .grip { cursor: grab; color: var(--muted-foreground); font-size: 18px; user-select: none; }
.menu-item .mi-label { font-weight: 600; }
.menu-item .mi-route { color: var(--muted-foreground); font-size: 12px; font-family: var(--font-mono); }
.menu-item .mi-main { flex: 1; min-width: 0; }
.menu-item .mi-actions { display: flex; gap: 8px; align-items: center; }
.menu-item.sortable-ghost { opacity: .4; }
.menu-item.sortable-chosen { box-shadow: var(--shadow-md); }
.menu-item.inactive { opacity: .55; }
.menu-item.child { margin-left: 32px; border-left: 3px solid var(--primary); }
.menu-item .nest { background: transparent; border: 1px solid var(--border); color: var(--foreground);
  border-radius: var(--radius); width: 30px; height: 30px; cursor: pointer; font-size: 15px; line-height: 1; }
.menu-item .nest:hover { background: var(--muted); }

/* ------------------------------ sticky-header document table ------------------------------ */
.table-wrap { position: relative; }
/* overflow:hidden (used for rounded corners) would clip a sticky header, so
   the sticky variant drops it and shades the header instead. */
.table.sticky { overflow: visible; }
.table.sticky thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--muted);
  box-shadow: inset 0 -1px 0 var(--border);
}
.small { font-size: 11px; }

/* status badges */
.status {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.status-received    { background: #e0edff; color: #1e40af; }
.status-in_progress { background: #fef3c7; color: #92400e; }
.status-follow_up   { background: #ffe4e6; color: #9f1239; }
.status-done        { background: #dcfce7; color: #166534; }
.status-cancelled   { background: #e5e7eb; color: #4b5563; }
html.dark .status-received    { background: #1e3a5f; color: #bfdbfe; }
html.dark .status-in_progress { background: #4a3a10; color: #fde68a; }
html.dark .status-follow_up   { background: #4c1d24; color: #fecdd3; }
html.dark .status-done        { background: #14331f; color: #bbf7d0; }
html.dark .status-cancelled   { background: #374151; color: #d1d5db; }

/* notification bell */
.bell { position: relative; font-size: 18px; line-height: 1; }
.bell:hover { text-decoration: none; }
.bell-badge {
  position: absolute;
  top: -7px; right: -9px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #dc2626; color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
}
.mobilebar .bell { margin-left: auto; }

/* notifications panel (dashboard) */
.notif-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: calc(var(--radius) + 4px);
  padding: 14px 18px;
  margin: 16px 0;
}
.notif-panel.empty { border-left-color: var(--border); }
.notif-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.notif-head h2 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.notif-head .bell-badge { position: static; }
.notif-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.notif-list li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.notif-type {
  font-size: 11px; font-weight: 600; border-radius: 999px; padding: 2px 8px;
  background: var(--accent); color: var(--accent-foreground);
}
.notif-followup { background: #ffe4e6; color: #9f1239; }
html.dark .notif-followup { background: #4c1d24; color: #fecdd3; }

/* document metadata grid (view page) */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px 18px;
  margin: 14px 0;
  padding: 14px 16px;
  background: var(--muted);
  border-radius: calc(var(--radius) + 4px);
}
.meta-grid .meta-lbl {
  display: block; font-size: 11px; color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px;
}
.status-form { margin: 0; }
.status-form select { padding: 4px 8px; }
select[multiple] { width: 100%; padding: 4px; }

/* notification read-receipt panel (admin, view page) */
.read-status { margin: 16px 0; }
.read-status h2 { margin: 0 0 4px; font-size: 16px; }
.read-yes { color: #166534; font-weight: 600; }
.read-no  { color: #b45309; font-weight: 600; }
html.dark .read-yes { color: #86efac; }
html.dark .read-no  { color: #fbbf24; }

/* ------------------------------ responsive tables / forms ------------------------------ */
@media (max-width: 860px) {
  .table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .table.sticky thead th { position: static; }
  .table .details { white-space: normal; }
  .filter { flex-direction: column; align-items: stretch; }
  .menu-item { flex-wrap: wrap; }
}

/* ------------------------------ textareas & tags ------------------------------ */
textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  background: var(--background);
  color: var(--foreground);
  border: 1px solid var(--input);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
  min-height: 120px;
}
textarea:focus { outline: 2px solid var(--ring); outline-offset: 1px; border-color: var(--ring); }

a.tag-link { text-decoration: none; margin: 2px 2px 0 0; }
a.tag-link:hover { filter: brightness(1.06); text-decoration: none; }
.doc-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }

/* ------------------------------ clickable people ------------------------------ */
a.person-link { color: var(--primary); font-weight: 600; cursor: pointer; }
a.person-link:hover { text-decoration: underline; }

/* ------------------------------ faceted search ------------------------------ */
.facets { background: var(--card); border: 1px solid var(--border); border-radius: calc(var(--radius) + 4px); padding: 14px 16px; margin: 12px 0 18px; }
.facet-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 14px; }
.facet-grid label { margin: 0; font-size: 13px; }
.facet-actions { display: flex; gap: 10px; margin-top: 12px; }

/* ------------------------------ modal ------------------------------ */
.modal { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.5); padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--card); color: var(--card-foreground); border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 6px); width: 100%; max-width: 560px; max-height: 80vh; overflow: auto; box-shadow: var(--shadow-lg); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-x { background: transparent; border: 0; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted-foreground); }
.modal-body { padding: 16px 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); text-align: right; }
.pm-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.pm-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
