:root {
    --bg: #ddd8c6;
    --surface: #f6f3ea;
    --surface-alt: #ece6d4;
    --border: #d2cab0;
    --border-strong: #b7b08f;
    --text: #313414;
    --muted: #6f7450;
    --primary: #4a4d18;
    --primary-hover: #3f4214;
    --accent: #adb282;

    --success-bg: #dfe5c8;
    --success-text: #3f4214;
    --error-bg: #efe5d8;
    --error-text: #7a5a3a;
    --warning-bg: #e7dfc3;
    --warning-text: #6a5b2a;
    --info-bg: #d8dcc0;
    --info-text: #4a4d18;
    --neutral-bg: #ece6d4;

    --shadow-sm: 0 1px 2px rgba(49, 52, 20, 0.05);
    --shadow-md: 0 10px 30px rgba(49, 52, 20, 0.08);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --sidebar-width: 260px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    font-family: Inter, Segoe UI, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.bg-orbs {
    display: none;
}

.page-shell {
    min-height: 100vh;
    display: flex;
    align-items: stretch;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 24px;
    position: sticky;
    top: 0;
    min-height: 100vh;
}

.content-area {
    flex: 1;
    min-width: 0;
    padding: 32px;
}

.content-area.auth-only {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.glass,
.glass-soft {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.brand-block {
    display: flex;
    gap: 14px;
    align-items: center;
    margin-bottom: 24px;
}

.brand-logo-img {
    width: 56px;
    height: 56px;
    object-fit: contain;
    display: block;
    flex-shrink: 0;
}

.brand-block h2,
.auth-card h1,
.section-head h1,
.card h2 {
    margin: 0;
    color: var(--text);
}

.brand-block p,
.section-head p,
.auth-card p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.nav-links {
    display: grid;
    gap: 6px;
}

.nav-links a {
    display: block;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text);
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-links a:hover {
    background: var(--surface-alt);
    color: var(--primary);
    text-decoration: none;
}

.user-panel {
    padding: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.user-panel small {
    display: block;
    color: var(--muted);
    margin-top: 2px;
}

.auth-wrap {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.auth-card {
    width: min(460px, 100%);
    padding: 32px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-md);
}

.login-logo-wrap {
    margin-bottom: 18px;
}

.login-logo {
    width: 220px;
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

.demo-note {
    margin-top: 18px;
    padding: 16px;
    text-align: left;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card,
.card {
    padding: 22px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 8px;
}

.stat-card strong {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
}

.split-grid {
    display: grid;
    grid-template-columns: minmax(320px, 0.95fr) minmax(420px, 1.2fr);
    gap: 20px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.ticket-card h3 {
    margin: 8px 0 14px;
    font-size: 18px;
}

.ticket-top {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
}

.medium-card {
    max-width: 760px;
}

.wide-card {
    max-width: 1100px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.form-grid.single {
    grid-template-columns: 1fr;
}

.form-grid .full {
    grid-column: 1 / -1;
}

.work-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

input,
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: #f8f6ef;
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(74, 77, 24, 0.12);
}

input:disabled,
select:disabled,
textarea:disabled {
    background: #efebdd;
    color: var(--muted);
    cursor: not-allowed;
}

textarea {
    min-height: 110px;
    resize: vertical;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.check-row input {
    width: auto;
    margin: 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 16px;
    border: 1px solid var(--primary);
    border-radius: 10px;
    background: var(--primary);
    color: #f8f6ef;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    text-decoration: none;
}

.btn-outline {
    background: #f8f6ef;
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-outline:hover {
    background: var(--surface-alt);
    border-color: var(--accent);
}

.btn-disabled,
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.alert {
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-weight: 600;
    border: 1px solid transparent;
}

.alert.success {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: #cdd7af;
}

.alert.error {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: #e0cfbb;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    min-width: 640px;
    border-collapse: collapse;
}

thead th {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
}

th,
td {
    padding: 14px 12px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

tbody tr:hover {
    background: #f2eedf;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    text-transform: capitalize;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge.open {
    background: #e7dfc3;
    color: #6a5b2a;
    border-color: #d7cca6;
}

.badge.in_progress {
    background: #d8dcc0;
    color: #4a4d18;
    border-color: #c3ca9f;
}

.badge.completed {
    background: #dfe5c8;
    color: #3f4214;
    border-color: #cdd7af;
}

.badge.neutral {
    background: var(--neutral-bg);
    color: #5a5f3d;
    border-color: var(--border);
}

.signature-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.signature-card {
    min-width: 0;
}

.signature-pad {
    width: 100%;
    height: 180px;
    display: block;
    background: #f8f6ef;
    border: 1px dashed var(--border-strong);
    border-radius: 10px;
    touch-action: none;
}

.sig-actions {
    margin-top: 10px;
}

.photo-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.photo-input-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.photo-input-item {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.photo-input-item input[type="file"] {
    flex: 1;
    min-width: 220px;
}

.add-photo-btn,
.btn-remove-photo {
    width: fit-content;
}

.photo-counter {
    display: inline-flex;
    width: fit-content;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    color: var(--muted);
    font-weight: 700;
}

.photo-counter.is-over-limit {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: #e0cfbb;
}

.photo-processing-status {
    flex-basis: 100%;
    color: var(--muted);
    font-size: 13px;
}

.form-submit-progress {
    margin-top: 10px;
    font-weight: 700;
    color: var(--muted);
}

/* PWA styles */
.pwa-actions {
    margin-bottom: 16px;
}

.pwa-install-btn {
    width: 100%;
}

.pwa-status-banner {
    position: sticky;
    top: 0;
    z-index: 9999;
    padding: 12px 16px;
    text-align: center;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}

.pwa-status-banner.is-offline {
    background: #7a5a3a;
    color: #fff;
}

.pwa-status-banner.is-online {
    background: #4a4d18;
    color: #fff;
}

.ios-install-tip[hidden],
.ios-install-tip[aria-hidden="true"] {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.ios-install-tip {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
}

.ios-install-tip__card {
    width: min(520px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    box-shadow: var(--shadow-md);
}

.ios-install-tip__card p {
    margin: 8px 0 16px;
    color: var(--muted);
}

@media (max-width: 1100px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .split-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 1024px) {
    .page-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-height: auto;
        position: static;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .signature-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .content-area,
    .sidebar {
        padding: 16px;
    }

    .auth-card,
    .card,
    .stat-card {
        padding: 18px;
    }

    .form-grid,
    .work-form,
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .user-panel {
        flex-direction: column;
        align-items: flex-start;
    }

    .photo-input-item {
        flex-direction: column;
        align-items: stretch;
    }

    .add-photo-btn,
    .btn-remove-photo,
    .sig-actions .btn,
    .form-grid .btn,
    .work-form .btn {
        width: 100%;
    }

    table {
        min-width: 560px;
    }

    .brand-block {
        align-items: center;
    }

    .brand-logo-img {
        width: 48px;
        height: 48px;
    }

    .login-logo {
        width: 180px;
    }

    .pwa-status-banner {
        font-size: 14px;
        padding: 10px 12px;
    }
}
.inline-reference-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.inline-reference-form input[type="text"] {
    width: 132px;
    min-width: 132px;
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
}

.btn-sm {
    padding: 8px 12px;
    font-size: 13px;
    min-height: auto;
}
