/* ── Dark (default) ── */
:root {
    --bg:      #0d1b2a;
    --surface: #111c2a;
    --surface2:#0f1a26;
    --border:  #1e3048;
    --text:    #e7ecff;
    --muted:   #a0b8cc;
    --primary: steelblue;
    --danger:  #c0392b;
    --success: #4caf50;
    --radius:  4px;
}

/* ── Light ── */
html.light {
    --bg:      #e2e2e2;
    --surface: #f8fafc;
    --surface2:#dfdfdf;
    --border:  #b8c8d8;
    --text:    #0f172a;
    --muted:   #334155;
    --primary: #2f5fa7;
    --danger:  #c0392b;
    --success: #2e7d32;
}

/* ---------- GENERAL ---------- */

body {
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
}

/* ---------- HEADER ---------- */

header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    position: relative;
}

.auth-bar {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
}

#login-inline {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 10px;
    position: absolute;
    top: 100%;
    right: 10px;
    z-index: 100;
    display: none;
    min-width: 220px;
}

#login-inline h3 {
    margin: 0 0 8px;
    font-size: 13px;
}

#auth-err {
    color: var(--danger);
    font-size: 11px;
    margin: 4px 0 0;
}

header h1 {
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.logo-box img {
    height: 32px;
    width: auto;
    display: block;
}

/* ---------- MAIN ---------- */

main {
    padding: 10px;
}

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

/* ---------- NAV ---------- */

nav {
    display: flex;
    flex-direction: column;
    width: 300px;
}

/* ---------- INPUTS ---------- */

input,
select,
textarea {
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 13px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border: 1px solid var(--primary);
}

/* ---------- BUTTONS ---------- */

button {
    background: var(--primary);
    border: 1px solid var(--primary);
    color: #fff;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 13px;
}

button:hover {
    opacity: 0.85;
}

/* ---------- TABLE (EXCEL STYLE) ---------- */

table {
    border-collapse: collapse;
    width: 100%;
    width: stretch;
    background: var(--surface);
}

th {
    background: var(--surface2);
    border: 1px solid var(--border);
    font-weight: 600;
    text-align: left;
    padding: 6px;
    color: var(--text);
}

td {
    border: 1px solid var(--border);
    padding: 5px;
    color: var(--text);
}

tr:nth-child(even) td {
    background: var(--surface2);
}

tr:nth-child(odd) td {
    background: var(--surface);
}

tr:hover td {
    filter: brightness(1.08);
}

.table {
    overflow-x: auto;
    width: stretch;
}

/* ---------- TEXTAREA ---------- */

textarea {
    width: 100%;
    width: stretch;
}

#taskNotes {
    min-height: 120px;
}

/* ---------- MODALS ---------- */

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 15px;
}

/* ---------- SMALL UI ITEMS ---------- */

.clear-button,
.delete-task-btn {
    background: var(--danger);
    border-color: var(--danger);
}

/* ---------- GRID / CALENDAR ---------- */

.year-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.day-block {
    border: 1px solid var(--border);
    height: 30px;
    font-size: 12px;
    background: var(--surface);
}

.day-block.today     { background: #1a3a1a; }
.day-block.has-data  { background: #1a2a3a; }

html.light .day-block.today    { background: #c6efce; }
html.light .day-block.has-data { background: #ddebf7; }

#detailsModal {
    display: none;
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    width: stretch;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
}

#closeModal {
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

/* ---------- THEME TOGGLE ---------- */

#theme-toggle {
    margin-left: auto;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 14px;
    padding: 3px 8px;
    cursor: pointer;
    border-radius: var(--radius);
}

#theme-toggle:hover {
    opacity: 1;
    border-color: var(--primary);
    color: var(--text);
}

/* ---------- JOB MANAGER ---------- */

.hidden {
    display: none;
}

/* daily task thumb strip */
.thumb-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.thumb-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 110px;
    position: relative;
    padding: 4px;
    border-radius: var(--radius);
}

.thumb-img {
    max-width: 100px;
    display: block;
    cursor: zoom-in;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.thumb-delete {
    position: absolute;
    top: -6px;
    right: -6px;
    z-index: 5;
    background: var(--danger);
    border-color: var(--danger);
}

.thumb-note,
.thumb-markup {
    width: 100%;
    font-size: 11px;
}

/* section control rows */
.ctrl-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-bottom: 8px;
}

/* device image cell */
.img-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.img-count {
    font-size: 11px;
    font-weight: 600;
    background: color-mix(in srgb, var(--primary) 20%, var(--surface2));
    border-radius: 10px;
    padding: 1px 7px;
    color: var(--text);
    min-width: 20px;
    text-align: center;
}

.img-select {
    max-width: 120px;
    font-size: 11px;
}

.img-markup-inp {
    width: 90px;
    font-size: 11px;
}

.collapsible-section.collapsed > *:not(.collapsible-header) {
    display: none;
}

.collapsible-header {
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    padding: 4px 0;
    margin: 0 0 4px;
    font-size: 0.95rem;
    color: var(--text);
}

.collapsible-header::after {
    content: " ▾";
    font-size: 0.75em;
    opacity: 0.45;
}

.collapsible-section.collapsed .collapsible-header::after {
    content: " ▸";
}

#task-log th,
#task-log td {
    padding: 4px 8px;
    border: 1px solid var(--border);
    font-size: 13px;
}

[contenteditable]:focus {
    background: color-mix(in srgb, var(--primary) 15%, var(--surface2));
    outline: 1px solid var(--primary);
}

#currentTaskTime {
    display: inline;
    font-weight: bold;
}

#missingList li {
    color: var(--danger);
    font-weight: bold;
}

#missingList li.missing-sensor {
    cursor: pointer;
}

#modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    justify-content: center;
    align-items: center;
    z-index: 100;
}

#modalContent {
    position: relative;
    background: var(--surface);
    padding: 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

#modalImage {
    margin: 0 auto;
    max-width: 90vw;
    max-height: 80vh;
    display: block;
    margin-bottom: 10px;
}

#modalFileName {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 10px;
    text-align: center;
    color: var(--text);
}

section {
    margin: 12px 0;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.seg-row {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 2px 0;
}

.seg-row.active {
    font-weight: 600;
}

.seg-badge {
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 3px;
    min-width: 46px;
    text-align: center;
    text-transform: uppercase;
    cursor: default;
}

.seg-badge.travel {
    background: rgba(59, 130, 246, 0.18);
    color: #93c5fd;
}

.seg-badge.work {
    background: rgba(34, 197, 94, 0.18);
    color: #86efac;
}

html.light .seg-badge.travel {
    background: #dbeafe;
    color: #1d4ed8;
}

html.light .seg-badge.work {
    background: #dcfce7;
    color: #15803d;
}

.seg-time {
    font-size: 12px;
    border-bottom: 1px dashed var(--border);
    padding: 0 2px;
    cursor: text;
    min-width: 52px;
    outline: none;
    color: var(--text);
}

.seg-arrow {
    font-size: 12px;
    color: var(--muted);
}

.seg-dur {
    font-size: 12px;
    color: var(--muted);
}

.seg-totals {
    font-size: 12px;
    margin-bottom: 6px;
    color: var(--muted);
}

.seg-totals span:first-child {
    margin-right: 12px;
}

.seg-empty {
    color: var(--muted);
    font-size: 12px;
}

.device-counted td {
    opacity: 0.55;
}

.device-counted td:first-child {
    opacity: 1;
}

input[type="checkbox"] {
    width: auto;
    padding: 0;
}

#deviceFilter {
    width: auto;
}

#exportDeviceCSV {
    float: right;
}

#deviceTableWrap {
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

#deviceTableWrap table {
    width: max-content;
    min-width: 100%;
}

#deviceTableWrap td {
    vertical-align: top;
}

#deviceTableWrap .col-check  { text-align: center; width: 36px; }
#deviceTableWrap .col-label  { min-width: 90px; }
#deviceTableWrap .col-serial,
#deviceTableWrap .col-model  { min-width: 100px; }
#deviceTableWrap .col-type,
#deviceTableWrap .col-status { min-width: 80px; }
#deviceTableWrap .col-location { min-width: 110px; }
#deviceTableWrap .col-ip     { min-width: 120px; }
#deviceTableWrap .col-mac    { min-width: 130px; }
#deviceTableWrap .col-notes-col { min-width: 150px; }
#deviceTableWrap .col-images { min-width: 180px; }

#deviceAddRow {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    padding: 4px 0;
}
#deviceTableWrap .col-act    { width: 36px; text-align: center; }

#dailyTasksBody td {
    padding: 4px 6px;
    vertical-align: top;
}

.markup-label {
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 3px;
    color: var(--muted);
}

.btn-sm {
    font-size: 11px;
}

.img-card {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.img-thumb {
    height: 90px;
    width: auto;
    object-fit: cover;
    border-radius: var(--radius);
    cursor: pointer;
    border: 1px solid var(--border);
}

#scrollTopBtn {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    width: 42px !important;
    height: 42px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    font-size: 20px !important;
    background: rgba(70, 130, 180, 0.25) !important;
    border: 1px solid rgba(70, 130, 180, 0.35) !important;
    color: rgba(255, 255, 255, 0.75) !important;
    cursor: pointer;
    z-index: 999;
}

#scrollTopBtn:hover {
    background: rgba(70, 130, 180, 0.6) !important;
    opacity: 1 !important;
}

#taskSelect {
    width: 100%;
    max-width: 300px;
}

@media (max-width: 768px) {
    header button {
        width: auto;
    }

    #scrollTopBtn {
        width: 42px !important;
    }
}

/* ---------- TASK ROW ACTIVE ---------- */

.task-row-active td {
    background: color-mix(in srgb, var(--primary) 18%, var(--surface)) !important;
    border-top: 1px solid var(--primary) !important;
    border-bottom: 1px solid var(--primary) !important;
}

/* ---------- LINKS ASIDE ---------- */

#links-aside {
    position: fixed;
    top: 0;
    right: -360px;
    width: 340px;
    height: 100vh;
    background: var(--surface);
    border-left: 1px solid var(--border);
    z-index: 200;
    transition: right 0.25s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body.links-aside-open #links-aside {
    right: 0;
}

#links-aside iframe {
    flex: 1;
    border: none;
    width: 100%;
    display: block;
    background: var(--bg);
}

#links-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 199;
    background: rgba(0, 0, 0, 0.3);
}

body.links-aside-open #links-overlay {
    display: block;
}

#links-toggle {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 14px;
    padding: 3px 8px;
    cursor: pointer;
    border-radius: var(--radius);
}

#links-toggle:hover {
    opacity: 1;
    border-color: var(--primary);
    color: var(--text);
}
