/* KorPrint — PHP edition.  Lightweight, no Tailwind required. */
:root {
  --bg: #0f172a;
  --surface: #ffffff;
  --muted: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #0f172a;
  --primary-fg: #ffffff;
  --accent: #2563eb;
  --danger: #dc2626;
  --warning: #f59e0b;
  --success: #16a34a;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 2px 6px rgba(0,0,0,0.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--muted);
  color: var(--text);
  font-size: calc(13px * var(--font-scale, 1));
  line-height: 1.4;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg); color: #cbd5e1; padding: 12px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 4px 16px; border-bottom: 1px solid #1e293b; margin-bottom: 10px; }
.sidebar .brand img { width: 140px; height: auto; max-width: 100%; background: transparent;
  filter:
    drop-shadow( 1px  0 0 rgba(255,255,255,.85))
    drop-shadow(-1px  0 0 rgba(255,255,255,.85))
    drop-shadow( 0  1px 0 rgba(255,255,255,.85))
    drop-shadow( 0 -1px 0 rgba(255,255,255,.85))
    drop-shadow(0 0 6px rgba(148,197,255,.55)); }
.sidebar .brand strong { color: #fff; font-size: calc(14px * var(--font-scale, 1)); letter-spacing: .02em; }
.sidebar nav a { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 6px; color: #cbd5e1; font-size: calc(13px * var(--font-scale, 1)); }
.sidebar nav a:hover { background: #1e293b; color: #fff; text-decoration: none; }
.sidebar nav a.active { background: #1e293b; color: #fff; }
.sidebar nav a .count { margin-left: auto; font-size: calc(11px * var(--font-scale, 1)); color: #94a3b8; }
.sidebar .user { margin-top: auto; padding-top: 12px; border-top: 1px solid #1e293b; font-size: calc(12px * var(--font-scale, 1)); }
.sidebar form button { background: transparent; border: 0; color: #94a3b8; cursor: pointer; font-size: calc(12px * var(--font-scale, 1)); padding: 4px 0; }
.sidebar form button:hover { color: #fff; }

.main { padding: 16px; max-width: 100%; min-width: 0; overflow-x: auto; }
.flash { margin-bottom: 12px; padding: 8px 12px; border-radius: 6px; border: 1px solid; font-size: calc(13px * var(--font-scale, 1)); }
.flash.success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash.error   { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash.info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

h1 { font-size: calc(18px * var(--font-scale, 1)); margin: 0 0 12px; font-weight: 600; }
h2 { font-size: calc(14px * var(--font-scale, 1)); margin: 0 0 8px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
.card + .card { margin-top: 12px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.toolbar > * { margin: 0; }
.spacer { flex: 1; }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 16px; }
.dash-split { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; align-items: start; margin-bottom: 12px; }
.dash-split > .card { display: flex; flex-direction: column; min-height: 0; }
.dash-split > .card > h2 { flex: 0 0 auto; }
.dash-split .dash-chart-wrap { position: relative; height: 360px; width: 100%; }
.dash-split .dash-list-wrap { max-height: 360px; overflow: auto; }
@media (max-width: 900px) { .dash-split { grid-template-columns: 1fr; } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.tile .l { color: var(--text-muted); font-size: calc(11px * var(--font-scale, 1)); text-transform: uppercase; letter-spacing: .06em; }
.tile .v { font-size: calc(24px * var(--font-scale, 1)); font-weight: 600; margin-top: 4px; }
.tile a { color: inherit; }
.tile.danger .v { color: var(--danger); }
.tile.warning .v { color: var(--warning); }
.tile.success .v { color: var(--success); }

input[type=text], input[type=password], input[type=email], input[type=number], input[type=date],
textarea, select {
  font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 5px;
  background: #fff; color: var(--text); width: 100%; min-width: 0;
}
input:focus, textarea:focus, select:focus { outline: 2px solid #93c5fd; outline-offset: -1px; border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }

label { font-size: calc(11px * var(--font-scale, 1)); color: var(--text-muted); display: block; margin-bottom: 2px; }

.btn { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; font-size: calc(12px * var(--font-scale, 1)); border-radius: 5px; border: 1px solid var(--border); background: #fff; color: var(--text); cursor: pointer; text-decoration: none; }
.btn { justify-content: center; }
.btn:hover { background: var(--muted); text-decoration: none; }
.btn-primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn-primary:hover { background: #1e293b; color: #fff; }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 3px 8px; font-size: calc(11px * var(--font-scale, 1)); }

table { width: 100%; border-collapse: collapse; font-size: calc(12px * var(--font-scale, 1)); background: var(--surface); }
table th, table td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
table th { background: #f8fafc; font-weight: 500; color: var(--text-muted); font-size: calc(11px * var(--font-scale, 1)); text-transform: uppercase; letter-spacing: .04em; }
table tr:hover td { background: #f8fafc; }
table tr.clickable { cursor: pointer; }
table tr.edit-row > td { background: #f8fafc; padding: 10px 8px; }
table tr.edit-row input, table tr.edit-row select { padding: 4px 6px; font-size: calc(12px * var(--font-scale, 1)); }
table tr.row-display { cursor: pointer; }
table tr.row-display:hover td { background: #eef2ff; }

.row-actions a, .row-actions button { font-size: calc(11px * var(--font-scale, 1)); }

.badge { display: inline-block; padding: 1px 6px; border-radius: 999px; font-size: calc(10px * var(--font-scale, 1)); font-weight: 600; background: var(--muted); color: var(--text-muted); }
.badge.danger { background: #fee2e2; color: var(--danger); }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.success { background: #dcfce7; color: var(--success); }

.grid-2 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.grid-3 { display: grid; gap: 12px; grid-template-columns: repeat(3, 1fr); }
.grid-4 { display: grid; gap: 12px; grid-template-columns: repeat(4, 1fr); }
/* Equalized cards in a grid: same height, search box pinned to bottom */
.equal-cards > .card { display: flex; flex-direction: column; }
.equal-cards > .card > .card-foot { margin-top: auto; padding-top: 8px; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* Mobile: toolbar wraps, search fills remaining width */
.toolbar-search { display: flex; gap: 6px; align-items: center; }
.toolbar-search input { width: 260px; }
@media (max-width: 720px) {
  .toolbar { gap: 6px; }
  .toolbar > h1 { width: 100%; }
  .toolbar-search { flex: 1 1 100%; }
  .toolbar-search input { width: 100%; flex: 1; }
  .tabs { flex-wrap: wrap; }
}

/* Tables: horizontal scroll lives inside the card on narrow viewports */

.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: calc(12px * var(--font-scale, 1)); color: var(--text-muted); }

.tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 5px; overflow: hidden; }
.tabs a { padding: 5px 10px; font-size: calc(12px * var(--font-scale, 1)); color: var(--text-muted); }
.tabs a.active { background: var(--primary); color: #fff; }
.tabs a:hover:not(.active) { background: var(--muted); text-decoration: none; }

/* Dark theme: status tabs need visible hover + active contrast */
:root[data-theme="dark"] .tabs { border-color: var(--border); }
:root[data-theme="dark"] .tabs a { color: var(--text-muted); background: transparent; }
:root[data-theme="dark"] .tabs a:hover:not(.active) { background: #1e293b; color: var(--text); }
:root[data-theme="dark"] .tabs a.active { background: var(--primary); color: #fff; }

/* Logout button: distinct, matches the app button style */
.sidebar .btn-logout { width: 100%; background: #1e293b; color: #fff; border-color: #334155; }
.sidebar .btn-logout:hover { background: #334155; color: #fff; }
:root[data-theme="dark"] .sidebar .btn-logout { background: var(--primary); border-color: var(--primary); color: #fff; }
:root[data-theme="dark"] .sidebar .btn-logout:hover { background: #1d4ed8; }

.muted { color: var(--text-muted); }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }

/* Autocomplete dropdown */
.ac-wrap { position: relative; }
.ac-list { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-top: 0; max-height: 240px; overflow-y: auto; border-radius: 0 0 5px 5px; box-shadow: var(--shadow); }
.ac-list button { display: block; width: 100%; text-align: left; padding: 6px 8px; border: 0; background: transparent; cursor: pointer; font: inherit; }
.ac-list button:hover { background: var(--muted); }
.ac-list .small { font-size: calc(10px * var(--font-scale, 1)); color: var(--text-muted); }

/* Login */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--muted); }
.login-card { width: 320px; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 20px; box-shadow: var(--shadow); }
.login-card h1 { font-size: calc(16px * var(--font-scale, 1)); text-align: center; margin: 0 0 16px; }
.login-card .brand { text-align: center; margin-bottom: 12px; }
.login-card .brand img { height: 110px; width: auto; max-width: 100%; }
.login-card .brand img,
:root[data-theme="dark"] .login-card .brand img {
  filter:
    drop-shadow( 1px  0 0 rgba(255,255,255,.85))
    drop-shadow(-1px  0 0 rgba(255,255,255,.85))
    drop-shadow( 0  1px 0 rgba(255,255,255,.85))
    drop-shadow( 0 -1px 0 rgba(255,255,255,.85))
    drop-shadow(0 0 6px rgba(148,197,255,.55));
}

/* Font-size control */
.font-ctrl { display: inline-flex; align-items: center; gap: 2px; border: 1px solid #1e293b; border-radius: 999px; padding: 2px; }
.font-ctrl button { background: transparent; border: 0; color: #cbd5e1; cursor: pointer; width: 22px; height: 22px; border-radius: 999px; font-size: calc(12px * var(--font-scale, 1)); line-height: 1; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.font-ctrl button:hover { background: #1e293b; color: #fff; }

/* Theme toggle */
.theme-toggle { width: 32px; height: 32px; border-radius: 999px; border: 1px solid #1e293b; background: transparent; color: #cbd5e1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.theme-toggle:hover { background: #1e293b; color: #fff; }
.theme-toggle-icon { width: 14px; height: 14px; display: inline-block; border-radius: 50%; background: #fbbf24; box-shadow: inset -4px -2px 0 0 #0f172a; }
:root[data-theme="dark"] .theme-toggle-icon { background: #f8fafc; box-shadow: inset -4px -2px 0 0 transparent; }

/* ---------- DARK THEME ---------- */
:root[data-theme="dark"] {
  --bg: #020617;
  --surface: #0f172a;
  --muted: #0b1220;
  --border: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #2563eb;
  --primary-fg: #ffffff;
  --accent: #60a5fa;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 2px 8px rgba(0,0,0,.3);
}
:root[data-theme="dark"] body { background: var(--muted); color: var(--text); }
:root[data-theme="dark"] .sidebar { background: #020617; border-right: 1px solid #1e293b; }
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .tile { background: var(--surface); border-color: var(--border); }
:root[data-theme="dark"] table { background: var(--surface); color: var(--text); }
:root[data-theme="dark"] table th { background: #0b1220; color: var(--text-muted); }
:root[data-theme="dark"] table tr:hover td { background: #1e293b; }
:root[data-theme="dark"] table tr.edit-row > td { background: #0b1220; }
:root[data-theme="dark"] table tr.row-display:hover td { background: #1e293b; }
:root[data-theme="dark"] input, :root[data-theme="dark"] textarea, :root[data-theme="dark"] select {
  background: #0b1220; color: var(--text); border-color: var(--border);
}
:root[data-theme="dark"] .btn { background: #0b1220; color: var(--text); border-color: var(--border); }
:root[data-theme="dark"] .btn:hover { background: #1e293b; }
:root[data-theme="dark"] .btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
:root[data-theme="dark"] .btn-primary:hover { background: #1d4ed8; }
:root[data-theme="dark"] .btn-danger { background: #1e293b; color: #fca5a5; border-color: #7f1d1d; }
:root[data-theme="dark"] .flash.success { background: #052e1f; border-color: #14532d; color: #86efac; }
:root[data-theme="dark"] .flash.error   { background: #2c0a0a; border-color: #7f1d1d; color: #fca5a5; }
:root[data-theme="dark"] .flash.info    { background: #0a1d3a; border-color: #1e3a8a; color: #93c5fd; }
:root[data-theme="dark"] .login-shell { background: #020617; }
:root[data-theme="dark"] .login-card  { background: #0f172a; border-color: #1e293b; color: var(--text); }
:root[data-theme="dark"] .ac-list     { background: #0f172a; border-color: var(--border); }
:root[data-theme="dark"] .ac-list button { color: var(--text); }
:root[data-theme="dark"] .ac-list button:hover { background: #1e293b; }
:root[data-theme="dark"] .badge { background: #0a1d3a; color: #93c5fd; }
:root[data-theme="dark"] .badge.success { background: #052e1f; color: #86efac; }
:root[data-theme="dark"] .badge.danger  { background: #2c0a0a; color: #fca5a5; }
:root[data-theme="dark"] .badge.warning { background: #2a1c05; color: #fcd34d; }

/* ---------- Messenger ---------- */
.badge-msg { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 6px; border-radius: 999px; font-size: calc(10px * var(--font-scale, 1)); font-weight: 700; background: #1e293b; color: #cbd5e1; }
.badge-msg.has-unread { background: var(--danger); color: #fff; }
.sidebar nav a .badge-msg.has-unread { margin-left: auto; }
.sidebar nav a .badge-msg[hidden] { display: none; }

.msg-list .msg-row { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text); text-decoration: none; }
.msg-list .msg-row:last-child { border-bottom: 0; }
.msg-list .msg-row:hover { background: var(--muted); text-decoration: none; }
.msg-row-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: var(--primary-fg); display: flex; align-items: center; justify-content: center; font-weight: 700; text-transform: uppercase; flex: 0 0 auto; }
.msg-row-body { flex: 1 1 auto; min-width: 0; }
.msg-row-top { display: flex; gap: 8px; align-items: baseline; }
.msg-row-title { font-weight: 600; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-row-time { font-size: calc(11px * var(--font-scale, 1)); white-space: nowrap; }
.msg-row-preview { font-size: calc(12px * var(--font-scale, 1)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.msg-users { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px 12px; max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; padding: 8px; background: #fff; }
:root[data-theme="dark"] .msg-users { background: #0b1220; }
.msg-user { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px; cursor: pointer; }

.chat-card { padding: 0; display: flex; flex-direction: column; height: calc(100vh - 140px); min-height: 380px; max-width: 100%; }
.chat-stream { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--muted); }
.chat-msg { max-width: 78%; padding: 6px 10px; border-radius: 12px; box-shadow: var(--shadow); word-wrap: break-word; }
.chat-msg.mine   { align-self: flex-end;  background: var(--primary); color: var(--primary-fg); border-bottom-right-radius: 4px; }
.chat-msg.theirs { align-self: flex-start; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-msg-sender { font-size: calc(10px * var(--font-scale, 1)); font-weight: 700; opacity: .8; margin-bottom: 2px; }
.chat-msg-body { white-space: pre-wrap; font-size: calc(13px * var(--font-scale, 1)); }
.chat-msg-time { font-size: calc(10px * var(--font-scale, 1)); opacity: .7; margin-top: 4px; text-align: right; }
.chat-msg.mine .chat-msg-time { color: rgba(255,255,255,.85); }
.chat-msg-image { display: block; margin-top: 4px; }
.chat-msg-image img { max-width: 100%; max-height: 240px; border-radius: 6px; display: block; }
.chat-msg-file { display: inline-block; margin-top: 4px; padding: 4px 8px; background: rgba(0,0,0,.08); border-radius: 6px; color: inherit; text-decoration: none; font-size: calc(12px * var(--font-scale, 1)); }
.chat-msg.mine .chat-msg-file { background: rgba(255,255,255,.2); color: #fff; }
.chat-msg-file:hover { text-decoration: underline; }

.chat-composer { border-top: 1px solid var(--border); padding: 10px; background: var(--surface); display: flex; flex-direction: column; gap: 8px; }
.chat-composer textarea { resize: none; min-height: 44px; max-height: 160px; }
.chat-composer-row { display: flex; align-items: center; gap: 8px; }
.chat-attach-btn { cursor: pointer; }

@media (max-width: 720px) {
  .chat-card { height: calc(100vh - 120px); }
  .chat-msg { max-width: 92%; }
}