/* ---------------------------------------------------------------------
   QualityWebMS app shell — dark theme, tablet-first (11" Android Chrome).
   Touch targets >= 48px everywhere. No CDN assets — must render fully
   offline (Cache-First PWA shell).
   --------------------------------------------------------------------- */

:root {
    --qms-bg: #0f1115;
    --qms-surface: #181b21;
    --qms-surface-raised: #21252d;
    --qms-border: #2e333d;
    --qms-text: #e8eaed;
    --qms-text-muted: #9aa0ac;
    --qms-accent: #4c8dff;
    --qms-accent-text: #06131f;
    --qms-online: #2fb872;
    --qms-offline: #e5534b;
    --qms-warn: #e0a339;
    --qms-bar-height: 56px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--qms-bg);
    color: var(--qms-text);
    font-family: 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    color-scheme: dark;
}

h1:focus { outline: none; }

a, .btn-link { color: var(--qms-accent); }

label { display: block; margin-bottom: 0.35rem; color: var(--qms-text-muted); font-size: 0.9rem; }

.validation-message { color: var(--qms-offline); }

#blazor-error-ui {
    background: var(--qms-warn);
    color: #1a1200;
    bottom: 0;
    box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.4);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: var(--qms-border);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--qms-accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    color: var(--qms-text);
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

/* ---- App shell ---- */

.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-bar {
    height: var(--qms-bar-height);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1rem;
    background: var(--qms-surface);
    border-bottom: 1px solid var(--qms-border);
    color: var(--qms-text);
    flex-shrink: 0;
}

.app-name { font-weight: 700; font-size: 1.1rem; }

.app-bar-links { display: flex; gap: 0.5rem; margin-right: auto; }

.app-bar-links a {
    color: var(--qms-text-muted);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    min-height: 48px;
    display: flex;
    align-items: center;
    border-radius: 6px;
}

.app-bar-links a.active { background: var(--qms-surface-raised); color: var(--qms-text); }

.connectivity-pill, .sync-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #06131f;
}

.connectivity-pill.online { background: var(--qms-online); }
.connectivity-pill.offline { background: var(--qms-offline); color: #fff; }
.sync-badge { background: var(--qms-warn); }

/* Which data model this head runs against: SQLite offline (WASM/OPFS) or MSSQL online (server). */
.mode-chip {
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--qms-text);
    background: var(--qms-surface-raised);
    border: 1px solid var(--qms-border, rgba(255, 255, 255, 0.2));
    white-space: nowrap;
}

.app-content { flex: 1; padding: 1rem; max-width: 960px; margin: 0 auto; width: 100%; }

/* ---- Forms & controls ---- */

button, input, select, textarea {
    min-height: 48px;
    font-size: 1rem;
    font-family: inherit;
    color: var(--qms-text);
    background: var(--qms-surface-raised);
    border: 1px solid var(--qms-border);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
}

input:focus, select:focus, textarea:focus, button:focus-visible {
    outline: 2px solid var(--qms-accent);
    outline-offset: 1px;
}

input[readonly] { color: var(--qms-text-muted); }

button {
    cursor: pointer;
    background: var(--qms-accent);
    color: var(--qms-accent-text);
    border: none;
    font-weight: 600;
}

button:disabled { opacity: 0.55; cursor: not-allowed; }

button[type="button"]:not(.primary) {
    background: var(--qms-surface-raised);
    color: var(--qms-text);
    border: 1px solid var(--qms-border);
}

/* Two columns in landscape (typical tablet-in-hand orientation), one column in portrait so form
   rows never get cramped against the on-screen keyboard. */
.entry-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (orientation: landscape) and (min-width: 700px) {
    .entry-grid { grid-template-columns: 1fr 1fr; }
}

.stats-grid { grid-template-columns: repeat(2, 1fr); }
@media (orientation: landscape) and (min-width: 700px) {
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

.stat-tile {
    background: var(--qms-surface);
    border: 1px solid var(--qms-border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    text-align: center;
}

.stat-tile strong { font-size: 1.4rem; }

.entry-actions { display: flex; gap: 0.75rem; margin-top: 1rem; }

.report-list { list-style: none; padding: 0; margin: 0; }

.report-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--qms-surface);
    border: 1px solid var(--qms-border);
    border-radius: 8px;
}

.report-list a { color: var(--qms-text); text-decoration: none; }

.status-chip {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #06131f;
}

.status-chip.Draft { background: var(--qms-text-muted); }
.status-chip.Pending, .status-chip.Uploading { background: var(--qms-warn); }
.status-chip.Uploaded { background: var(--qms-online); }
.status-chip.Failed { background: var(--qms-offline); color: #fff; }

.measurement-row {
    background: var(--qms-surface);
    border: 1px solid var(--qms-border);
    border-radius: 8px;
    padding: 0.75rem;
}

.measurement-row.out-of-tolerance { background: #3a1414; border-color: var(--qms-offline); }

.out-of-tolerance-tag { color: var(--qms-offline); display: block; margin-top: 0.25rem; }

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.photo-tile { display: flex; flex-direction: column; gap: 0.35rem; }

.photo-grid img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--qms-border);
}

.outbox-table {
    width: 100%;
    border-collapse: collapse;
}

.outbox-table th, .outbox-table td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--qms-border);
}

.single-tab-guard {
    max-width: 32rem;
    margin: 3rem auto;
    text-align: center;
    padding: 1rem;
}

.update-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--qms-surface-raised);
    color: var(--qms-text);
    border-top: 1px solid var(--qms-border);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    z-index: 1100;
}
