/* ==========================================================================
   Telegram CRM — Stylesheet
   Signal-console visual language: an ops panel for a team that pulls
   customers in from live Telegram groups. Ink-navy chrome, a single
   "online" signal accent, monospaced system data (IDs / passwords),
   Khmer serif for headings, Khmer sans for everything else.
   ========================================================================== */

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

:root {
    /* Color */
    --ink:        #17233D;
    --ink-soft:   #4C5872;
    --bg:         #F3F5F9;
    --surface:    #FFFFFF;
    --line:       #E0E4EC;
    --accent:     #2F6FED;
    --accent-dark:#1F4FBD;
    --accent-soft:#EAF0FE;
    --signal:     #16A38A;
    --signal-soft:#E4F6F2;
    --danger:     #E0483E;
    --danger-soft:#FDECEA;
    --row-alt:    #F8FAFC;

    /* Type */
    --font-display: "Noto Serif Khmer", "Khmer OS", serif;
    --font-body:    "Noto Sans Khmer", "Khmer OS", sans-serif;
    --font-mono:    "JetBrains Mono", ui-monospace, monospace;

    /* Layout */
    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 1px 2px rgba(23, 35, 61, 0.04), 0 8px 24px rgba(23, 35, 61, 0.06);

    /* Header ជានិច្ចជា Navy ដដែល ទោះកែ Dark/Light Mode ក៏ដោយ (ដាច់ដោយឡែកពី --ink) */
    --header-bg: rgba(255, 255, 255, 0.7);
    --header-shadow: 0 8px 32px rgba(23, 35, 61, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

/* --------------------------------------------------------------------
   Dark Mode — ដាក់ attribute data-theme="dark" លើ <html> ដើម្បីប្តូរ
   -------------------------------------------------------------------- */
html[data-theme="dark"] {
    --ink:        #E8ECF6;
    --ink-soft:   #A9B4CC;
    --bg:         #0E1424;
    --surface:    #172038;
    --line:       #2A3552;
    --accent:     #5B8DFF;
    --accent-dark:#8FB0FF;
    --accent-soft:#1E2A4D;
    --signal:     #2BD1AF;
    --signal-soft:#123B34;
    --danger:     #FF7A70;
    --danger-soft:#3A1E1C;
    --row-alt:    #131B30;
    --header-bg: rgba(23, 32, 56, 0.75);
    --header-shadow: 0 8px 32px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* --------------------------------------------------------------------
   Header — every non-login page starts here
   -------------------------------------------------------------------- */
header {
    position: sticky;
    top: 16px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 16px 32px;
    margin: 16px 20px 0;
    background: var(--header-bg);
    border-radius: 16px;
    box-shadow: var(--header-shadow);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* --- Logo + ចំណងជើង (ខាងឆ្វេងបារ) --- */
.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.header-logo {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: #FFFFFF;
    box-shadow: 0 4px 12px rgba(22, 163, 138, 0.25);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.header-logo-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    background: var(--signal-soft);
}

header h1 {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 22px;
    color: var(--ink);
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* the "online" signal — a small pulsing dot before the title,
   a quiet nod to a CRM whose data streams in live from Telegram */
header h1::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--signal);
    box-shadow: 0 0 0 0 rgba(22, 163, 138, 0.55);
    animation: pulse 2.2s ease-out infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(22, 163, 138, 0.55); }
    70%  { box-shadow: 0 0 0 8px rgba(22, 163, 138, 0); }
    100% { box-shadow: 0 0 0 0 rgba(22, 163, 138, 0); }
}

.logout-link {
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 600;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--line);
    white-space: nowrap;
    transition: all 0.2s ease;
    background: rgba(255, 255, 255, 0.4);
}

.logout-link:hover,
.logout-link:focus-visible {
    color: var(--ink);
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.6);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(47, 111, 237, 0.15);
}

/* --------------------------------------------------------------------
   Header user info / nav (Multi-User: Admin + Sub Agent)
   -------------------------------------------------------------------- */
.header-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.current-user {
    color: var(--ink-soft);
    font-size: 13.5px;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    font-weight: 600;
    padding-right: 12px;
    border-right: 1px solid var(--line);
}

.role-tag {
    font-size: 10px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.role-admin {
    background: rgba(47, 111, 237, 0.15);
    color: var(--accent);
    border: 1px solid rgba(47, 111, 237, 0.3);
}

.role-agent {
    background: rgba(22, 163, 138, 0.15);
    color: var(--signal);
    border: 1px solid rgba(22, 163, 138, 0.3);
}

.nav-link {
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 600;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--line);
    white-space: nowrap;
    transition: all 0.2s ease;
    background: rgba(255, 255, 255, 0.4);
}

.nav-link:hover,
.nav-link:focus-visible {
    color: var(--ink);
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.6);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(47, 111, 237, 0.15);
}

/* --- ប៊ូតុងប្តូរ Dark/Light Mode --- */
.theme-toggle {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    background: rgba(255, 255, 255, 0.3);
    border: 1.5px solid var(--line);
    border-radius: 50%;
    color: var(--ink-soft);
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
    background: rgba(255, 255, 255, 0.5);
    border-color: var(--accent);
    color: var(--ink);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(47, 111, 237, 0.15);
}

.theme-toggle:active { transform: translateY(1px) scale(0.96); }

.view-only-note {
    color: var(--ink-soft);
    font-size: 13px;
    font-style: italic;
}

/* --------------------------------------------------------------------
   Sub Agent permission management (users.html)
   -------------------------------------------------------------------- */
.perm-tag {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-dark);
    white-space: nowrap;
}

.permission-form select {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    font-size: 13px;
    background: var(--surface);
    color: var(--ink);
}

.reset-pw-btn {
    border: none;
    cursor: pointer;
    font-family: inherit;
    background: rgba(144, 166, 166, 0.363);
}
.reset-pw-btn:hover { background: #b8b0f0; }

.users-page-error {
    margin: 14px 28px 0;
}

/* --------------------------------------------------------------------
   Search box (dashboard)
   -------------------------------------------------------------------- */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin: 24px 28px 0;
}

.search-box {
    display: flex;
    gap: 10px;
    max-width: 640px;
    flex: 1;
}

.search-box input[type="text"] {
    flex: 1;
}

.search-box button {
    flex-shrink: 0;
}

/* --- Add Customer button (toolbar) --- */
.button-group {
    display: flex;
    gap: 8px;
}

.add-link {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    padding: 11px 20px;
    border-radius: var(--radius-sm);
    background: var(--signal);
    color: #FFFFFF;
    font-weight: 600;
    font-size: 14.5px;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s ease, transform 0.05s ease;
}

.add-link:hover,
.add-link:focus-visible {
    background: #128F78;
}

.add-link:active { transform: translateY(1px); }

.total {
    margin: 14px 28px 0;
    color: var(--ink-soft);
    font-size: 13.5px;
    font-weight: 500;
}

/* --------------------------------------------------------------------
   Table (dashboard)
   -------------------------------------------------------------------- */
.table-wrap {
    margin: 14px 28px 32px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 920px;
}

thead th {
    position: sticky;
    top: 0;
    background: var(--surface);
    text-align: left;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 13px 16px;
    border-bottom: 2px solid var(--accent);
    white-space: nowrap;
}

tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
    color: var(--ink);
    white-space: nowrap;
}

tbody tr:nth-child(even) { background: var(--row-alt); }

tbody tr:hover { background: var(--accent-soft); }

tbody tr:last-child td { border-bottom: none; }

/* Customer ID & PW read as system data, not prose */
tbody td:nth-child(3),
tbody td:nth-child(4) {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--ink-soft);
    letter-spacing: 0.02em;
}

/* Group / Web columns as quiet source tags */
tbody td:nth-child(7),
tbody td:nth-child(8) {
    font-size: 12.5px;
}

tbody td:nth-child(7):not(:empty),
tbody td:nth-child(8):not(:empty) {
    color: var(--signal);
    font-weight: 600;
}

.empty {
    text-align: center;
    color: var(--ink-soft);
    padding: 40px 16px;
    white-space: normal;
}

.edit-link {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #FFFFFF;
    font-weight: 600;
    font-size: 13.5px;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s ease, transform 0.05s ease;
    border: none;
    cursor: pointer;
    font-family: var(--font-body);
}

.edit-link:hover,
.edit-link:focus-visible {
    background: var(--accent-dark);
    text-decoration: none;
}

.edit-link:active { transform: translateY(1px); }

/* --- Status badge --- */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-active {
    background: var(--signal-soft);
    color: var(--signal);
}

.badge-inactive {
    background: var(--row-alt);
    color: var(--ink-soft);
    border: 1px solid var(--line);
}

tbody tr.row-inactive { opacity: 0.6; }
tbody tr.row-inactive:hover { opacity: 1; }

/* --- Action buttons (Edit / Active-Inactive / Delete) --- */
.action-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.inline-form { display: inline-flex; margin: 0; }

.btn-toggle,
.btn-delete {
    padding: 6px 12px;
    font-size: 12.5px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, transform 0.05s ease;
}

.btn-toggle:active,
.btn-delete:active { transform: translateY(1px); }

.btn-pause {
    background: var(--row-alt);
    color: var(--ink-soft);
    border: 1px solid var(--line);
}

.btn-pause:hover { background: var(--line); }

.btn-resume {
    background: var(--signal-soft);
    color: var(--signal);
    border: 1px solid rgba(22, 163, 138, 0.25);
}

.btn-resume:hover { background: #D5F0EA; }

.btn-delete {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid rgba(224, 72, 62, 0.25);
}

.btn-delete:hover { background: #FBDAD7; }

/* --------------------------------------------------------------------
   Form controls — shared by search box, edit box, login box
   -------------------------------------------------------------------- */
input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 14.5px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]::placeholder,
input[type="password"]::placeholder {
    color: #9AA4B8;
}

input[type="text"]:focus,
input[type="password"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

button {
    padding: 11px 20px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #FFFFFF;
    font-family: var(--font-body);
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.05s ease;
}

button:hover { background: var(--accent-dark); }

button:active { transform: translateY(1px); }

button:focus-visible,
a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --------------------------------------------------------------------
   Edit page
   -------------------------------------------------------------------- */
.edit-box {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 20px;
    max-width: 720px;
    margin: 28px;
    padding: 28px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.edit-box label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-soft);
}

.edit-box input { margin-bottom: 4px; }

.edit-box button {
    grid-column: 1 / -1;
    justify-self: start;
    margin-top: 8px;
    padding: 12px 28px;
}

.edit-box .error {
    grid-column: 1 / -1;
}

.error {
    margin: 0 0 4px;
    padding: 10px 14px;
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid rgba(224, 72, 62, 0.25);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
}

/* --------------------------------------------------------------------
   Login page
   -------------------------------------------------------------------- */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(560px circle at 50% 32%, rgba(22, 163, 138, 0.18), transparent 60%),
        var(--ink);
}

.login-box {
    width: 100%;
    max-width: 380px;
    padding: 36px 32px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.login-box h1 {
    margin: 0 0 24px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 22px;
    color: var(--ink);
    text-align: center;
}

.login-box label {
    display: block;
    margin: 16px 0 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-soft);
}

.login-box label:first-of-type { margin-top: 0; }

.login-box button {
    width: 100%;
    margin-top: 24px;
    padding: 12px;
    font-size: 15px;
}

/* --------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------- */
@media (max-width: 640px) {
    header { padding: 16px 18px; }
    header h1 { font-size: 18px; }

    .toolbar,
    .total,
    .table-wrap,
    .edit-box {
        margin-left: 18px;
        margin-right: 18px;
    }

    .search-box { flex-direction: column; }

    .add-link { justify-content: center; }

    .edit-box {
        grid-template-columns: 1fr;
        padding: 22px;
    }
}

/* --------------------------------------------------------------------
   Add Customer — Modal
   -------------------------------------------------------------------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(23, 35, 61, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-overlay.open { 
    display: flex; 
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-box {
    width: 100%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.4);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    background: linear-gradient(135deg, rgba(47, 111, 237, 0.05) 0%, rgba(22, 163, 138, 0.05) 100%);
    border-bottom: 1px solid var(--line);
}

.modal-header h2 {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 18px;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-close {
    background: rgba(255, 255, 255, 0.5);
    padding: 8px 12px;
    color: var(--ink-soft);
    font-size: 18px;
    line-height: 1;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-close:hover { 
    background: rgba(47, 111, 237, 0.15);
    color: var(--accent);
    transform: scale(1.1);
}

.modal-box .edit-box {
    margin: 0;
    box-shadow: none;
    border: none;
    padding: 24px;
    gap: 2px;
}

.modal-box .edit-box label {
    color: var(--ink-soft);
    font-weight: 600;
    margin-bottom: 2px;
    font-size: 13px;
}

.modal-box .edit-box input {
    border: 1.5px solid var(--line);
    transition: all 0.2s ease;
    margin-bottom: 6px;
}

.modal-box .edit-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.modal-box .edit-box button {
    padding: 11px 24px;
    font-size: 14px;
    font-weight: 600;
    margin-top: 12px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.modal-box .error {
    margin-bottom: 16px;
}

@media (max-width: 640px) {
    .modal-box .edit-box { grid-template-columns: 1fr; padding: 20px; }
}
/* --------------------------------------------------------------------
   Sidebar Menu — Navigation ខាងឆ្វេង (Logo នៅលើ + Menu នៅក្រោម)
   -------------------------------------------------------------------- */
.app-shell {
    display: flex;
    align-items: flex-start;
    min-height: 100vh;
}

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

.sidebar {
    width: 232px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 26px;
    padding: 22px 14px 24px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    z-index: 30;
    transition: transform 0.25s ease;
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }

/* --- Logo នៅផ្នែកលើបំផុតរបស់ Sidebar --- */
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px 18px;
    border-bottom: 1px solid var(--line);
}

.sidebar-logo img {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: #FFFFFF;
    box-shadow: 0 4px 12px rgba(22, 163, 138, 0.25);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.sidebar-logo-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    background: var(--signal-soft);
}

.sidebar-logo span {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 15.5px;
    color: var(--ink);
    line-height: 1.25;
}

/* --- Menu (នៅក្រោម Logo) --- */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.18s ease;
}

.sidebar-link:hover { background: var(--accent-soft); color: var(--accent-dark); }

.sidebar-link.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.sidebar-link.disabled {
    opacity: 0.55;
    cursor: default;
    pointer-events: none;
}

.sidebar-link .icon { font-size: 15px; flex-shrink: 0; }

.sidebar-soon {
    margin-left: auto;
    font-size: 10px;
    font-weight: 700;
    color: var(--ink-soft);
    background: var(--row-alt);
    border: 1px solid var(--line);
    padding: 2px 7px;
    border-radius: 999px;
    letter-spacing: 0.2px;
}

/* --- Group ដែលបើក/បិទបាន (របាយការណ៍ / Settings) --- */
.sidebar-group { border: none; }

.sidebar-group summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--ink);
    font-weight: 700;
    font-size: 14px;
    user-select: none;
}

.sidebar-group summary::-webkit-details-marker { display: none; }
.sidebar-group summary::marker { content: ""; }

.sidebar-group summary:hover { background: var(--row-alt); }

.sidebar-group summary .icon { font-size: 15px; flex-shrink: 0; }

.sidebar-group summary .chevron {
    margin-left: auto;
    font-size: 10px;
    color: var(--ink-soft);
    transition: transform 0.2s ease;
}

.sidebar-group[open] summary .chevron { transform: rotate(90deg); }

.sidebar-sublist {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 0 6px 14px;
    margin-top: 2px;
    border-left: 1.5px solid var(--line);
}

.sidebar-sublist .sidebar-link { font-size: 13.5px; padding: 8px 12px; }

/* --- Hamburger Toggle (Mobile ប៉ុណ្ណោះ) --- */
.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--line);
    background: rgba(255, 255, 255, 0.5);
    color: var(--ink);
    font-size: 17px;
    cursor: pointer;
    flex-shrink: 0;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(23, 35, 61, 0.5);
    z-index: 25;
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.18);
    }

    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-overlay { display: block; }

    .sidebar-toggle { display: inline-flex; }
}

/* --------------------------------------------------------------------
   Settings pages (/settings, /settings/schedule)
   -------------------------------------------------------------------- */
.settings-wrap {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 860px;
    margin: 28px;
}

.settings-banner {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 600;
}

.settings-banner-success {
    background: var(--signal-soft);
    color: var(--signal);
    border: 1px solid rgba(22, 163, 138, 0.25);
}

.settings-banner-restart {
    background: var(--accent-soft);
    color: var(--accent-dark);
    border: 1px solid rgba(47, 111, 237, 0.25);
    font-weight: 500;
}

.settings-group {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px 24px 6px;
}

.settings-group h2 {
    margin: 0 0 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
    font-family: var(--font-display);
    font-size: 16.5px;
    font-weight: 700;
    color: var(--ink);
}

.settings-field {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    padding: 16px 0;
    border-bottom: 1px solid var(--line);
}

.settings-field:last-child { border-bottom: none; }

.settings-field-label { flex: 1; min-width: 0; }

.settings-field-label label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

.settings-field-help {
    margin: 5px 0 0;
    font-size: 12.5px;
    color: var(--ink-soft);
    line-height: 1.55;
}

.settings-restart-tag {
    display: inline-block;
    margin-top: 7px;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid rgba(224, 72, 62, 0.25);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.2px;
}

.settings-field-input {
    flex: 0 0 280px;
    max-width: 280px;
}

.settings-field-input input[type="text"],
.settings-field-input input[type="password"],
.settings-field-input input[type="number"],
.settings-field-input select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 14px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.settings-field-input input:focus,
.settings-field-input select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.settings-secret-badge {
    display: block;
    margin-top: 7px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--signal);
}

/* --- Toggle Switch (Bool Field) --- */
.settings-toggle {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    cursor: pointer;
}

.settings-toggle input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-track {
    position: relative;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
    background: var(--line);
    border-radius: 999px;
    transition: background 0.15s ease;
}

.toggle-track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: #FFFFFF;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.15s ease;
}

.settings-toggle input:checked + .toggle-track { background: var(--accent); }
.settings-toggle input:checked + .toggle-track::after { transform: translateX(18px); }

.settings-toggle input:focus-visible + .toggle-track {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.toggle-state {
    min-width: 30px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-soft);
    text-align: right;
}

.settings-submit-bar {
    display: flex;
    justify-content: flex-end;
    padding: 4px 0 8px;
}

.settings-submit-bar button { padding: 12px 30px; }

@media (max-width: 700px) {
    .settings-wrap { margin: 16px; }

    .settings-field {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .settings-field-input { max-width: none; }

    .settings-toggle { justify-content: flex-start; }
}
