* { box-sizing: border-box; }

:root {
    --blue-50:  #eef6fb;
    --blue-100: #b9d9ec;
    --blue-300: #6fa8c9;
    --blue-500: #0c6fa8;
    --blue-600: #0a5d8f;
    --blue-700: #0a4d82;
    --blue-900: #0a2c4f;

    --ink:       #0e2438;
    --ink-soft:  #4d6478;
    --surface:   #ffffff;
    --bg:        #eef6fb;

    --radius:    14px;
    --radius-sm: 8px;
    --shadow:    0 8px 24px rgba(10, 44, 79, 0.12);
    --shadow-sm: 0 2px 8px rgba(10, 44, 79, 0.10);

    --font: "Segoe UI", "Inter", Roboto, Arial, sans-serif;
    --font-mono: "Cascadia Code", "Consolas", "Courier New", monospace;

    --field-bg:     #ffffff;
    --field-border: #d6e6f0;
    --divider:      #eef2f6;
}

/* Set by shared.js (localStorage 'wqTheme') on <html> — see _applyTheme(). */
[data-theme="dark"] {
    --ink:       #e6edf5;
    --ink-soft:  #9bb0c4;
    --surface:   #16222f;
    --bg:        #0c1620;
    --blue-50:   #1c2e3f;
    --shadow:    0 8px 24px rgba(0, 0, 0, 0.45);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);

    --field-bg:     #1c2a3a;
    --field-border: #2e4459;
    --divider:      #233344;
}

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
}

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

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

@keyframes pulseDot {
    0%, 100% { box-shadow: 0 0 0 0 rgba(12, 111, 168, 0.55); }
    70%      { box-shadow: 0 0 0 7px rgba(12, 111, 168, 0); }
}

@keyframes drift {
    0%   { transform: translate(0, 0) scale(1); }
    50%  { transform: translate(-12px, 18px) scale(1.06); }
    100% { transform: translate(0, 0) scale(1); }
}

.hidden { display: none !important; }

button {
    background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
    color: #fff;
    border: none;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.2px;
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
    box-shadow: var(--shadow-sm);
}

button:hover  { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(10, 77, 130, 0.35); filter: brightness(1.05); }
button:active { transform: translateY(0); filter: brightness(0.95); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ── App header ─────────────────────────────────────────────────────── */

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: linear-gradient(120deg, var(--blue-900), var(--blue-700));
    border-bottom: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 4px 16px rgba(10, 44, 79, 0.25);
}

.header-stats {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-last-update {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.3;
}

.header-last-update-label {
    font-size: 10px;
    color: var(--blue-100);
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.header-last-update-value {
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    font-family: var(--font-mono);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-btn {
    background: rgba(255,255,255,0.08);
    box-shadow: none;
    padding: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.icon-btn svg { width: 18px; height: 18px; color: var(--blue-100); }

.icon-btn:hover { background: rgba(255,255,255,0.16); transform: none; box-shadow: none; }

.user-menu-wrap { position: relative; }

.user-icon-btn img { width: 20px; height: 20px; opacity: 0.95; }

.user-dropdown {
    position: absolute;
    top: 46px;
    right: 0;
    min-width: 190px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 8px;
    display: flex;
    flex-direction: column;
    z-index: 150;
    animation: fadeInUp 0.18s ease;
}

.dropdown-welcome {
    font-size: 15px;
    font-weight: 700;
    color: var(--ink-soft);
    padding: 6px 10px 8px;
    border-bottom: 1px solid var(--divider);
    margin-bottom: 4px;
}

.user-dropdown a {
    color: var(--ink);
    text-decoration: none;
    font-size: 14px;
    padding: 9px 10px;
    border-radius: 6px;
    transition: background 0.15s ease;
}

.user-dropdown a:hover { background: var(--blue-50); }

#logoutMenuItem { color: #c0392b; }

.header-logo {
    width: 38px;
    height: auto;
    filter: drop-shadow(0 0 6px rgba(185, 217, 236, 0.5)) brightness(1.25);
}

.brand-sub {
    font-size: 13px;
    color: var(--blue-100);
    opacity: 0.9;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-weight: 600;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2be08a;
    display: inline-block;
    margin-left: 6px;
    animation: pulseDot 2s infinite;
}

.live-dot.offline {
    background: #ff4444;
    animation: none;
}

.live-dot.new-data {
    background: #ffd700;
}

.hidden { display: none !important; }

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-actions span {
    color: var(--blue-100);
    font-size: 13px;
    margin-right: 4px;
    display: flex;
    align-items: center;
}

/* ── Side navigation drawer ──────────────────────────────────────────── */

.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 44, 79, 0.35);
    z-index: 90;
    animation: fadeIn 0.2s ease;
}

.side-drawer {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 230px;
    background: var(--surface);
    box-shadow: var(--shadow);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 76px 12px 16px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
}

.side-drawer.open { transform: translateX(0); }

.drawer-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.15s ease, color 0.15s ease;
}

.drawer-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.drawer-item:hover { background: var(--blue-50); }

.drawer-item.active {
    background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
    color: #fff;
}

.board-context-bar { padding: 14px 20px 0; display: flex; justify-content: flex-end; }

.pane.table-wrap { margin: 16px 20px 20px; }

#mapPane.pane {
    height: calc(100vh - 110px);
    padding: 0 20px 20px;
    display: flex;
    gap: 16px;
    /* Leaflet's internal control/tile z-index goes up to ~1000 — trap it in
       its own stacking context so it can never render above the drawer,
       overlay or account dropdown (z-index 90/100/150). */
    position: relative;
    z-index: 1;
}

.map-day-panel {
    flex: 0 0 220px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: fit-content;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 14px;
}

.map-day-panel label {
    font-size: 12px;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 700;
}

.map-day-panel select {
    background: var(--field-bg);
    border: 1.5px solid var(--field-border);
    color: var(--ink);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 14px;
}

.map-day-info {
    font-size: 12px;
    color: var(--ink-soft);
    line-height: 1.5;
}

/* Toolbar's left:50% now centers over just the map (not the day panel too) —
   moved the positioned-ancestor role here off #mapPane. */
.map-area-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
    height: 100%;
}

#mapPane #map {
    width: 100%;
    height: 100%;
}

.register-panel {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid #e3edf4;
    animation: fadeInUp 0.3s ease;
}

.register-panel input {
    background: var(--field-bg);
    border: 1.5px solid var(--field-border);
    color: var(--ink);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.register-panel input:focus {
    outline: none;
    border-color: var(--blue-500);
}

#changePasswordMsg.ok { color: #1aa260; font-size: 13px; }
#changePasswordMsg.error { color: #e0463e; font-size: 13px; }

.table-wrap h3 {
    font-size: 13px;
    color: var(--blue-700);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin: 0;
    font-weight: 700;
}

.pane-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.stat-last-time {
    font-size: 0.78em;
    color: var(--ink-soft);
    font-weight: 400;
}

.stats-charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 24px;
}

.section-subtitle {
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    margin: 28px 0 4px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--blue-100);
}

.feed-pie-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 2;
    min-width: 0;
}

.feed-pie-card {
    flex: 1 1 200px;
    min-width: 180px;
    max-width: 260px;
}

.feed-pie-label {
    font-size: 0.82em;
    font-weight: 600;
    color: var(--ink-soft);
    text-align: center;
    margin-bottom: 4px;
}

.feed-pond-section {
    width: 100%;
}

.feed-pond-title {
    font-size: 0.92em;
    font-weight: 700;
    color: var(--blue-600);
    margin: 12px 0 6px;
    padding-left: 4px;
}

.feed-pie-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-overlay.hidden { display: none; }

.modal-box {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.22);
    padding: 20px 24px 24px;
    width: min(680px, 92vw);
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-title {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--blue-700);
}
[data-theme="dark"] .modal-title { color: #fff; }

.compare-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--ink-soft);
    margin: 16px 0 8px;
}

.compare-table { width: 100%; border-collapse: collapse; }
.compare-table th, .compare-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--field-border);
    font-size: 13px;
}
.compare-table th { font-weight: 700; color: var(--ink-soft); font-size: 12px; }
.compare-table td.best  { color: #16a34a; font-weight: 700; }
.compare-table td.worst { color: #dc2626; font-weight: 700; }
.compare-delta { color: var(--ink-soft); font-size: 12px; }

/* ── Login / Register screen ───────────────────────────────────────── */

.login-screen {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    overflow: hidden;
    background: radial-gradient(circle at 20% 20%, var(--blue-100) 0%, var(--bg) 45%),
                linear-gradient(160deg, var(--bg) 0%, #dcedf6 100%);
}

.login-screen::before,
.login-screen::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(12,111,168,0.16), transparent 70%);
    animation: drift 9s ease-in-out infinite;
}

.login-screen::before { width: 420px; height: 420px; top: -120px; left: -100px; }
.login-screen::after   { width: 340px; height: 340px; bottom: -100px; right: -80px; animation-delay: 2s; }

.login-box {
    position: relative;
    z-index: 1;
    width: 340px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 32px 30px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.6);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    animation: fadeInUp 0.5s ease;
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.login-logo {
    width: 190px;
    height: auto;
    margin-bottom: 2px;
}

.login-brand span {
    font-size: 11px;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.login-box h2 {
    margin: 0 0 2px;
    font-size: 17px;
    text-align: center;
    color: var(--ink);
}

.login-box input {
    background: var(--field-bg);
    border: 1.5px solid var(--field-border);
    color: var(--ink);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-box input:focus {
    outline: none;
    border-color: var(--blue-500);
    box-shadow: 0 0 0 3px rgba(12, 111, 168, 0.15);
}

.login-box button { margin-top: 4px; }

.robot-id-row {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}
.robot-id-row select {
    flex: 0 0 auto;
    background: var(--field-bg);
    border: 1.5px solid var(--field-border);
    color: var(--ink);
    padding: 10px 8px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
}
.robot-id-row input[type="number"] {
    flex: 1;
    min-width: 0;
    -moz-appearance: textfield;
}
.robot-id-row input[type="number"]::-webkit-inner-spin-button,
.robot-id-row input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }
.robot-id-sep {
    font-weight: bold;
    color: var(--ink);
    font-size: 16px;
}

.login-box a {
    color: var(--blue-600);
    font-size: 12px;
    text-align: center;
    text-decoration: none;
}

.login-box a:hover { text-decoration: underline; }

#loginMsg.ok { color: #1aa260; font-size: 13px; text-align: center; }
#loginMsg.error { color: #e0463e; font-size: 13px; text-align: center; }

/* ── Dashboard layout ───────────────────────────────────────────────── */

#dashboard { animation: fadeIn 0.35s ease; }

.stats-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px 4px;
}

.map-toolbar {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    gap: 16px;
}

.map-draw-btn {
    flex: 0 0 auto;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: transparent;
    box-shadow: none;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--blue-700);
    cursor: pointer;
    font-weight: 700;
    font-size: 16px;
}

.map-draw-btn svg { width: 30px; height: 30px; filter: drop-shadow(0 1px 3px rgba(0,0,0,0.6)); }

.map-draw-btn-active {
    background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
    color: #fff;
}

.map-clear-btn { color: #c0392b; }

.map-save-btn { color: #00C853; }

.field-area-tooltip {
    font-weight: 700;
    color: var(--blue-900);
    background: rgba(255,255,255,0.92);
}

.stat-card {
    flex: 1;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 14px 18px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--blue-500);
    animation: fadeInUp 0.4s ease both;
}

.stat-card .stat-label {
    font-size: 11px;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card .stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--blue-900);
    font-family: var(--font-mono);
    margin-top: 2px;
}

#map {
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid #fff;
}

.table-wrap {
    overflow-y: auto;
    padding: 16px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    animation: fadeInUp 0.4s ease;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th, td {
    padding: 9px 10px;
    text-align: left;
    border-bottom: 1px solid var(--divider);
    white-space: nowrap;
}

th {
    color: var(--blue-700);
    position: sticky;
    top: 0;
    background: var(--surface);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.sort-arrows {
    display: inline-flex;
    flex-direction: column;
    margin-left: 5px;
    vertical-align: middle;
    line-height: 1;
}

.sort-arrow {
    cursor: pointer;
    font-size: 8px;
    line-height: 8px;
    opacity: 0.35;
    user-select: none;
}

.sort-arrow:hover {
    opacity: 0.8;
}

.sort-arrow.active {
    opacity: 1;
    color: var(--blue-700);
}

tbody tr {
    transition: background 0.15s ease;
    animation: fadeIn 0.3s ease;
}

tbody tr:hover { background: var(--blue-50); }

.cell-lat, .cell-lon { font-family: var(--font-mono); color: var(--ink-soft); font-size: 12px; }

/* pH status chip */
.ph-chip {
    display: inline-block;
    min-width: 46px;
    text-align: center;
    padding: 3px 9px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
    color: #fff;
}

/* ── Dashboard data table extras ───────────────────────────────────── */

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--blue-50); }

.small-btn {
    padding: 5px 10px;
    font-size: 12px;
    margin-right: 4px;
    background: linear-gradient(135deg, var(--blue-300), var(--blue-500));
}

.danger-btn { background: linear-gradient(135deg, #e0746a, #c0392b); }

.actions-cell { white-space: nowrap; }

.edit-input {
    width: 70px;
    background: var(--field-bg);
    border: 1.5px solid var(--field-border);
    color: var(--ink);
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 12px;
}

.edit-input:focus { outline: none; border-color: var(--blue-500); }

/* Device UID/Username/Password are long strings — a fixed 70px input would
   shrink that column and shift the whole row sideways. Fill the column's
   already-established width (set by the display rows) instead. */
.edit-input-wide { width: 100%; box-sizing: border-box; }

/* ── Day detail: gauges, alarm banner, charts ──────────────────────── */

.clickable-row-light { cursor: pointer; transition: background 0.15s ease; }
.clickable-row-light:hover { background: var(--blue-50); }

.alarm-banner {
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 14px;
    margin: 14px 0;
    animation: fadeInUp 0.3s ease;
}

.alarm-banner.safe    { background: #e3f9ed; color: #1aa260; border: 1px solid #b6ebce; }
.alarm-banner.warning { background: #fff7e0; color: #b8860b; border: 1px solid #f3df9c; }
.alarm-banner.danger  { background: #fdeceb; color: #c0392b; border: 1px solid #f3b6b0; }

.gauge-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.gauge-card {
    flex: 1;
    background: var(--bg);
    border-radius: var(--radius);
    padding: 14px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.gauge-title {
    font-size: 12px;
    color: var(--blue-700);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    margin-bottom: 6px;
}

.gauge-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--blue-900);
    font-family: var(--font-mono);
    margin-top: -8px;
}

[data-theme="dark"] .gauge-title,
[data-theme="dark"] .gauge-value,
[data-theme="dark"] .table-wrap h3,
[data-theme="dark"] th,
[data-theme="dark"] .stat-card .stat-value,
[data-theme="dark"] .sort-arrow.active {
    color: #fff;
}

.gauge-unit {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-top: 2px;
}

.precision-row {
    display: flex;
    gap: 14px;
    margin-bottom: 18px;
}

.precision-card {
    flex: 1;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
}

.chart-card {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.gauge-row .chart-card {
    flex: 1;
    margin-bottom: 0;
    min-width: 0;
}

.chart-card canvas { max-height: 260px; }

.chart-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    gap: 12px;
    flex-wrap: wrap;
}

.chart-month-select {
    background: var(--field-bg);
    border: 1.5px solid var(--field-border);
    color: var(--ink);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
}
.chart-month-select:focus { outline: none; border-color: var(--blue-500); }

/* ── "Thông tin" page: editable form (user) / read-only view (admin) ─── */

.profile-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 420px;
}

.profile-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 700;
}

.profile-form input,
.profile-form select {
    background: var(--field-bg);
    border: 1.5px solid var(--field-border);
    color: var(--ink);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    text-transform: none;
    font-weight: 400;
}

.profile-form input:focus,
.profile-form select:focus { outline: none; border-color: var(--blue-500); }
.profile-form input:disabled { background: var(--bg); color: var(--ink-soft); cursor: not-allowed; }

.adminkey-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.adminkey-row input {
    flex: 1;
    font-family: monospace;
}

/* Theme select in admin.html's account dropdown (no personal "Thông tin" form there) */
.dropdown-theme {
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    color: var(--ink-soft);
}

.dropdown-theme select {
    background: var(--field-bg);
    border: 1.5px solid var(--field-border);
    color: var(--ink);
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.profile-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
}

.profile-view {
    display: flex;
    flex-direction: column;
    gap: 0;
    max-width: 480px;
}

.profile-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 4px;
    border-bottom: 1px solid var(--divider);
}

.profile-label {
    font-size: 12px;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 700;
}

.day-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.robot-marker-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
    border: 2px solid #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.robot-marker-icon svg {
    width: 18px;
    height: 18px;
    color: #fff;
}

/* ── Mobile / Responsive ─────────────────────────────────────────────── */

/* Horizontal scroll for all data tables */
.table-wrap { overflow-x: auto; }

@media (max-width: 767px) {
    /* Header */
    header { padding: 10px 14px; }
    .brand-sub { font-size: 11px; }
    .header-actions button:not(.icon-btn) { font-size: 12px; padding: 7px 12px; }

    /* Stats bar (admin — cards row below header) */
    .stats-bar { flex-wrap: wrap; gap: 10px; padding: 12px 14px 4px; }
    .stat-card  { flex: 1 1 calc(50% - 5px); min-width: 120px; }

    /* Pane margins */
    .pane.table-wrap { margin: 10px 10px 14px; }

    /* Data tables — ensure min-width so they scroll rather than squish.
       Scoped to .table-wrap to avoid affecting the compare modal table. */
    .table-wrap table { min-width: 520px; }
    /* Compare modal table: let it scroll within the modal */
    .modal-box { overflow-x: auto; }

    /* Map pane — stack day panel below map on portrait screens */
    #mapPane.pane {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 110px);
        padding: 0 10px 14px;
    }
    /* flex: 0 0 auto prevents flexbox from ignoring the explicit height */
    .map-area-wrap { flex: 0 0 auto; height: 55vw; min-height: 260px; }
    /* Set height directly on #map so Leaflet can measure it (height:100% fails
       when parent's height is not derived from an explicit ancestor height) */
    #mapPane #map  { height: 55vw; min-height: 260px; }
    .map-day-panel { flex: none; width: 100%; flex-direction: row; flex-wrap: wrap; gap: 10px; }
    .map-day-panel label { flex: 1 1 120px; display: flex; flex-direction: column; gap: 4px; }
    .map-day-panel select { width: 100%; }
    #mapDayInfo { width: 100%; }

    /* Gauge / precision rows — wrap to 2 per row */
    .gauge-row     { flex-wrap: wrap; }
    .precision-row { flex-wrap: wrap; }
    .gauge-card     { flex: 1 1 calc(50% - 8px); min-width: 120px; }
    .precision-card { flex: 1 1 calc(50% - 7px); min-width: 110px; }

    /* Day detail header — stack buttons below title */
    .day-detail-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .day-detail-header > div { display: flex; flex-wrap: wrap; gap: 6px; }

    /* Stats charts grid — single column on mobile */
    .stats-charts-grid { grid-template-columns: 1fr; }

    /* Login box */
    .login-box { width: calc(100vw - 32px); max-width: 340px; padding: 24px 20px; }

    /* Modal */
    .modal-box { padding: 16px 14px 20px; }

    /* Register panel — wrap on mobile */
    .register-panel { flex-wrap: wrap; }

    /* Feed pie cards — full width on mobile */
    .feed-pie-card { max-width: 100%; }

    /* Board context bar padding */
    .board-context-bar { padding: 10px 14px 0; }

    /* Profile form — full width */
    .profile-form { max-width: 100%; }
}

@media (max-width: 479px) {
    header { padding: 8px 10px; }
    .header-logo { width: 28px; }
    .brand-sub { font-size: 10px; letter-spacing: 0; }

    /* Stat cards — single column */
    .stat-card      { flex: 1 1 100%; }
    /* Gauge / precision cards — stack fully */
    .gauge-card     { flex: 1 1 100%; }
    .precision-card { flex: 1 1 100%; }

    /* Map day panel — stacked selects */
    .map-day-panel label { flex: 1 1 100%; }

    /* Chart canvas — slightly lower to fit screen */
    .chart-card canvas { max-height: 200px; }
}
