/* ===== SMPD SHARED THEME — "Armory" tactical design system ===== */
/* ใช้ร่วมกันทุกหน้า | dark = default, light via [data-theme="light"] */

@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@400;500;600;700&family=Noto+Sans+Thai:wght@400;500;600;700&display=swap');

/* ===== TOKENS ===== */
:root,
[data-theme="dark"] {
    color-scheme: dark;
    --bg: #14110f;
    --bg-body: #14110f;
    --card: #1c1815;
    --card-2: #241f1b;
    --border: #342c26;
    --border-strong: #4a3f36;
    --text: #ece6e0;
    --text-muted: #9a8f86;
    --text-dim: #6f655d;
    --primary: #ff7a1a;
    --primary-hover: #ff8f3d;
    --primary-ink: #1a0f06;
    --primary-tint: rgba(255, 122, 26, 0.12);
    --primary-line: rgba(255, 122, 26, 0.45);
    --success: #4ade80;
    --warning: #fbbf24;
    --danger: #f05252;
    --info: #60a5fa;
    --c-blue: #5aa9ff;
    --c-pink: #ff6b9a;
    --c-red: #ff4d3a;
    --c-cyan: #7fd4ff;

    /* fonts / shape / motion */
    --font-head: 'Chakra Petch', 'Noto Sans Thai', sans-serif;
    --font-body: 'Noto Sans Thai', 'Chakra Petch', sans-serif;
    --radius: 4px;
    --radius-sm: 3px;
    --radius-xs: 2px;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
    --ease: 140ms ease;

    /* legacy aliases (untouched pages) */
    --sidebar-bg: var(--card);
    --row-bg: var(--card-2);
    --border-subtle: var(--border);
    --accent: var(--primary);
    --primary-gradient: var(--primary);
    --primary-glow: transparent;
    --bg-card: var(--card);
    --input-bg: var(--card-2);
    --text-main: var(--text);
    --text-sub: var(--text-muted);
}

[data-theme="light"] {
    color-scheme: light;
    --bg: #f4f1ee;
    --bg-body: #f4f1ee;
    --card: #ffffff;
    --card-2: #f7f4f1;
    --border: #e3dcd5;
    --border-strong: #cfc5bb;
    --text: #1c1815;
    --text-muted: #6f655d;
    --text-dim: #9a8f86;
    --primary: #e8650a;
    --primary-hover: #d25a06;
    --primary-ink: #ffffff;
    --primary-tint: rgba(232, 101, 10, 0.10);
    --primary-line: rgba(232, 101, 10, 0.45);
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #2563eb;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
    --c-blue: #1d6fd1;
    --c-pink: #c2185b;
    --c-red: #d32f2f;
    --c-cyan: #0e7490;

    --sidebar-bg: var(--card);
    --row-bg: var(--card-2);
    --border-subtle: var(--border);
    --accent: var(--primary);
    --primary-gradient: var(--primary);
    --primary-glow: transparent;
    --bg-card: var(--card);
    --input-bg: var(--card-2);
    --text-main: var(--text);
    --text-sub: var(--text-muted);
}

/* ===== BASE ===== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    background: var(--bg);
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--bg-body);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    transition: background-color var(--ease), color var(--ease);
}

:where(h1, h2, h3, h4, h5, h6),
.font-head {
    font-family: var(--font-head);
    letter-spacing: 0.01em;
}

:where(a) {
    color: var(--primary);
}

::selection {
    background: var(--primary);
    color: var(--primary-ink);
}

:focus-visible {
    outline: 1px solid var(--primary);
    outline-offset: 2px;
}

.icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    vertical-align: -3px;
}

/* ===== PAGE HEADER ===== */
.page-header {
    padding: 28px 0 16px;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--primary);
}

.eyebrow {
    display: block;
    font-family: var(--font-head);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.page-title {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: clamp(26px, 5vw, 38px);
    line-height: 1.1;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--primary);
}

.page-sub {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 6px;
}

/* ===== CARD & SECTION HEADING ===== */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
}

.sec-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.sec-no {
    display: inline-block;
    font-family: var(--font-head);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--primary);
    background: var(--primary-tint);
    border: 1px solid var(--primary-line);
    border-radius: var(--radius-xs);
    padding: 2px 8px;
    letter-spacing: 0.04em;
}

.sec-title {
    font-family: var(--font-head);
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.sec-hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== BUTTONS ===== */
.btn,
.btn-primary,
.btn-secondary,
.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 10px 20px;
    font-family: var(--font-head);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.03em;
    line-height: 1.2;
    text-decoration: none;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color var(--ease), border-color var(--ease), color var(--ease);
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-ink);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-secondary {
    background: var(--card-2);
    border-color: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    border-color: var(--border-strong);
    color: var(--primary);
}

.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

.btn-block {
    width: 100%;
}

.btn:disabled,
.btn-primary:disabled,
.btn-secondary:disabled,
.btn-danger:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* slanted tab buttons */
.tab-slant {
    clip-path: polygon(10px 0, 100% 0, calc(100% - 10px) 100%, 0 100%);
    padding-left: 26px;
    padding-right: 26px;
}

/* ===== INPUTS ===== */
.input,
:where(input[type="text"], input[type="search"], input[type="number"], input[type="password"],
    input[type="email"], input[type="url"], input[type="date"], input[type="time"],
    input[type="datetime-local"], select, textarea) {
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--text);
    background: var(--card-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-height: 42px;
    padding: 9px 12px;
    transition: border-color var(--ease);
}

:where(textarea) {
    min-height: 90px;
    line-height: 1.5;
}

.input:focus,
:where(input, select, textarea):focus {
    border-color: var(--primary);
    outline: 1px solid var(--primary);
    outline-offset: 0;
}

::placeholder {
    color: var(--text-dim);
    opacity: 1;
}

.label {
    font-family: var(--font-head);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

/* ===== CHIPS / TAGS / BADGES ===== */
.chip,
.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    line-height: 1.3;
    padding: 5px 10px;
    color: var(--text);
    background: var(--card-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    cursor: default;
    transition: background-color var(--ease), border-color var(--ease), color var(--ease);
}

button.chip,
label.chip,
a.chip {
    cursor: pointer;
}

.chip:hover {
    border-color: var(--border-strong);
}

.chip.active,
.chip.selected,
.chip[aria-pressed="true"] {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-ink);
}

.badge {
    display: inline-block;
    font-family: var(--font-head);
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border);
    background: var(--card-2);
    color: var(--text-muted);
}

.badge-success { color: var(--success); border-color: currentColor; background: transparent; }
.badge-warning { color: var(--warning); border-color: currentColor; background: transparent; }
.badge-danger  { color: var(--danger);  border-color: currentColor; background: transparent; }
.badge-info    { color: var(--info);    border-color: currentColor; background: transparent; }

/* ===== TABLES ===== */
.table-wrapper {
    overflow-x: hidden;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.modern-table,
.table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    table-layout: auto;
}

.modern-table th,
.table th {
    padding: 11px 16px;
    text-align: left;
    font-family: var(--font-head);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    background: var(--card);
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
}

.modern-table td,
.table td {
    padding: 13px 16px;
    font-size: 14.5px;
    line-height: 1.7;
    vertical-align: top;
    border: none;
    border-bottom: 1px solid var(--border);
    word-wrap: break-word;
    word-break: break-word;
    white-space: normal;
    max-width: none;
    min-width: 80px;
}

.modern-table tbody tr:not(.row-cat-header),
.table tbody tr {
    background: transparent;
    transition: background-color var(--ease);
}

.modern-table tbody tr:not(.row-cat-header):hover,
.table tbody tr:hover {
    background: var(--card-2);
}

/* first column (index) */
.modern-table td:first-child {
    width: 60px;
    text-align: center;
    font-family: var(--font-head);
    font-weight: 600;
    color: var(--text-muted);
}

.col-name {
    min-width: 280px !important;
}

/* category header row */
.row-cat-header td {
    background: var(--card-2) !important;
    color: var(--primary) !important;
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 14px;
    text-align: left !important;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    padding: 12px 16px !important;
    border-top: 1px solid var(--border-strong) !important;
    border-bottom: 1px solid var(--border-strong) !important;
    border-left: 2px solid var(--primary) !important;
    white-space: normal !important;
}

.col-fine,
.col-jail {
    min-width: 120px !important;
    white-space: nowrap !important;
    font-family: var(--font-head);
    font-weight: 600;
    color: var(--text);
    text-align: center;
}

.modern-table td:nth-child(n+3) {
    color: var(--text);
}

.text-red {
    color: var(--danger) !important;
    font-weight: 600;
}

.text-muted { color: var(--text-muted) !important; }
.text-primary { color: var(--primary) !important; }

/* ===== IMAGES / ZOOM ===== */
.rule-img {
    height: 40px;
    width: auto;
    object-fit: contain;
    vertical-align: middle;
    border-radius: var(--radius-xs);
    margin-right: 12px;
    border: 1px solid var(--border);
    transition: border-color var(--ease);
    cursor: zoom-in;
    display: inline-block;
}

.rule-img:hover {
    border-color: var(--primary);
}

.swal-zoom-image {
    max-height: 85vh !important;
    max-width: 100% !important;
    object-fit: contain !important;
    border-radius: var(--radius) !important;
    cursor: zoom-in;
    transition: transform 0.3s ease;
}

.swal-zoom-image.zoomed {
    transform: scale(2.5);
    cursor: zoom-out;
    user-select: none;
    -webkit-user-drag: none;
}

.swal2-html-container {
    overflow: hidden !important;
    max-height: 90vh !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
}

/* ===== FLOATING THEME TOGGLE ===== */
.floating-theme-toggle {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 42px;
    height: 42px;
    background: var(--card);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9999;
    box-shadow: var(--shadow);
    transition: border-color var(--ease), color var(--ease);
}

.floating-theme-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.floating-theme-toggle svg,
.theme-toggle svg,
#themeToggle svg {
    width: 18px;
    height: 18px;
    display: block;
}

/* ===== UTIL ===== */
.divider {
    height: 1px;
    background: var(--border);
    border: 0;
    margin: 16px 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .modern-table th,
    .modern-table td {
        padding: 10px 12px;
        font-size: 14px;
    }

    .modern-table td:first-child {
        width: 50px;
    }

    .row-cat-header td {
        font-size: 13px;
        padding: 10px 12px !important;
    }

    .card {
        padding: 18px;
    }
}

@media (max-width: 480px) {
    .modern-table th,
    .modern-table td {
        padding: 9px 10px;
        font-size: 13px;
    }

    .modern-table td:first-child {
        width: 40px;
    }

    .floating-theme-toggle {
        bottom: 14px;
        left: 14px;
    }
}

/* ===== NO TEXT SELECTION ON CONTROLS ===== */
/* กันลากเมาส์แล้วคลุมดำตัวหนังสือบนปุ่ม/เมนู/แท็บ/ชิป */
button,
[role="button"],
input[type="button"],
input[type="submit"],
input[type="reset"],
.btn, [class*="btn-"], [class*="-btn"],
.chip, .tab-btn, .tab, .tabs, .badge, .sec-no,
nav, .navbar, .nav-links, .nav-right, .sidebar,
label[for], .floating-theme-toggle, .theme-switch {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

nav a, .navbar a, .sidebar a, .nav-links a,
button img, button svg, .btn img, nav img, .navbar img, .sidebar img {
    -webkit-user-drag: none;
}
