:root {
    --ink: #0E1116;
    --ink-soft: #2A2F37;
    --paper: #FAF8F3;
    --paper-warm: #F2EEE5;
    --gold: #B8954A;
    --gold-deep: #8A6F38;
    --rule: #D9D2C2;
    --success: #2B7A4B;
    --success-bg: #E8F5ED;
    --danger: #9B3232;
    --danger-bg: #FFF0F0;
    --white: #FFFFFF;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(14,17,22,0.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--ink);
    background: var(--paper);
    -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

a { color: var(--gold-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== NAV ========== */
.nav {
    background: var(--ink); color: var(--paper);
    padding: 0 1.25rem;
    display: flex; align-items: center; justify-content: space-between;
    height: 56px; position: sticky; top: 0; z-index: 100;
}
.nav-brand {
    font-weight: 800; font-size: 1.1rem; letter-spacing: 0.06em;
    color: var(--paper); display: flex; align-items: center; gap: 0.5rem; text-decoration: none;
}
.nav-brand:hover { text-decoration: none; }
.nav-brand .accent { color: var(--gold); }
.nav-logo { width: 28px; height: 28px; border-radius: 5px; }
.nav-links { display: flex; gap: 1.25rem; }
.nav-links a {
    color: rgba(250,248,243,0.7); font-size: 0.88rem; font-weight: 500;
    letter-spacing: 0.02em; padding: 0.3rem 0; transition: color 0.15s;
}
.nav-links a:hover, .nav-links a.active { color: var(--paper); text-decoration: none; }
.nav-toggle { display: none; }

/* ========== CONTAINER ========== */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; flex: 1; }
.container-wide { max-width: 1600px; margin: 0 auto; padding: 1.5rem; flex: 1; }

/* ========== FLASH ========== */
.flash {
    padding: 0.75rem 1rem; border-radius: var(--radius);
    margin-bottom: 1.25rem; font-size: 0.9rem; font-weight: 500;
}
.flash-success { background: var(--success-bg); color: var(--success); border: 1px solid #B8E0C8; }
.flash-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #E8B0B0; }

/* ========== HEADINGS ========== */
h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 0.4rem; }
h2 { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 0.6rem; }
h3 { font-size: 1rem; font-weight: 700; margin-bottom: 0.5rem; color: var(--ink-soft); }
.subtitle { font-size: 0.95rem; color: var(--ink-soft); margin-bottom: 1.5rem; }

/* ========== CARD ========== */
.card {
    background: var(--white); border: 1px solid var(--rule);
    border-radius: var(--radius); padding: 1.25rem;
    margin-bottom: 1.25rem; box-shadow: var(--shadow);
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 0.75rem; padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--rule);
}
.card-header h2 { margin-bottom: 0; }

/* ========== GRID ========== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

/* ========== BUTTONS ========== */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 0.4rem; padding: 0.6rem 1.2rem;
    border: none; border-radius: var(--radius);
    font-size: 0.9rem; font-weight: 600; cursor: pointer;
    text-decoration: none; transition: opacity 0.15s; line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation; min-height: 44px;
}
.btn:hover { opacity: 0.88; text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-gold { background: var(--gold); color: var(--white); }
.btn-gold-deep { background: var(--gold-deep); color: var(--white); }
.btn-ink { background: var(--ink); color: var(--paper); }
.btn-outline { background: transparent; color: var(--ink-soft); border: 1px solid var(--rule); }
.btn-outline:hover { border-color: var(--ink-soft); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger-outline { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.82rem; min-height: 36px; }
.btn-lg { padding: 0.75rem 2rem; font-size: 1rem; }

/* ========== UPLOAD AREA ========== */
.upload-area {
    border: 2px dashed var(--rule); border-radius: var(--radius);
    padding: 1.5rem 1rem; text-align: center;
    transition: border-color 0.2s, background 0.2s;
}
.upload-area:hover, .upload-area.dragover { border-color: var(--gold); background: rgba(184,149,74,0.05); }
.upload-area input[type="file"] { display: none; }
.upload-area label { cursor: pointer; display: block; }
.upload-icon { font-size: 2rem; color: var(--gold); margin-bottom: 0.4rem; }
.upload-text { font-size: 0.95rem; color: var(--ink-soft); margin-bottom: 0.5rem; }

/* ========== TABLE ========== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th {
    background: var(--ink); color: var(--paper);
    padding: 0.55rem 0.65rem; text-align: left; font-weight: 700;
    font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap;
}
td {
    padding: 0.55rem 0.65rem; border-bottom: 1px solid var(--rule);
    color: var(--ink-soft); vertical-align: middle;
}
tr:nth-child(odd) td { background: var(--paper-warm); }

/* ========== PENDING LIST ========== */
.pending-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.7rem 0; border-bottom: 1px solid var(--rule); gap: 0.5rem;
}
.pending-item:last-child { border-bottom: none; }
.pending-info { display: flex; align-items: center; gap: 0.6rem; min-width: 0; flex: 1; }
.pending-icon {
    width: 36px; height: 36px; background: var(--paper-warm);
    border-radius: var(--radius); display: flex; align-items: center; justify-content: center;
    color: var(--gold-deep); font-weight: 800; font-size: 0.7rem; flex-shrink: 0;
}
.pending-name { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-status { font-size: 0.8rem; color: var(--gold-deep); }
.pending-actions { display: flex; gap: 0.4rem; flex-shrink: 0; flex-wrap: wrap; }

/* ========== FORM ========== */
.form-section {
    margin-bottom: 1.25rem; padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--rule);
}
.form-section:last-child { border-bottom: none; margin-bottom: 0; }
.form-section h3 {
    color: var(--gold-deep); font-size: 0.82rem;
    letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 0.75rem;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.7rem; }
.form-grid-narrow { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.7rem; }
.form-group { display: flex; flex-direction: column; gap: 0.2rem; }
.form-group label { font-size: 0.82rem; font-weight: 600; color: var(--ink-soft); }
.form-group input, .form-group select {
    padding: 0.55rem 0.6rem; border: 1px solid var(--rule);
    border-radius: 4px; font-size: 16px; background: var(--white);
    color: var(--ink); transition: border-color 0.15s; min-height: 44px;
}
.form-group input:focus, .form-group select:focus {
    outline: none; border-color: var(--gold); box-shadow: 0 0 0 2px rgba(184,149,74,0.15);
}

/* ========== SCORE FIELD ========== */
.score-field { display: flex; flex-direction: column; gap: 0.15rem; }
.score-field label { font-size: 0.8rem; font-weight: 600; color: var(--ink-soft); }
.score-field .score-sub { font-size: 0.68rem; color: var(--gold-deep); margin-top: -0.1rem; }
.score-field input {
    padding: 0.5rem; border: 1px solid var(--rule); border-radius: 4px;
    font-size: 16px; width: 100%; background: var(--white); color: var(--ink); min-height: 44px;
}
.score-field input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 2px rgba(184,149,74,0.15); }

/* ========== ZONE ROWS (single responsive set) ========== */
.zone-label {
    display: inline-block; padding: 0.2rem 0.5rem;
    color: var(--white); font-weight: 700; font-size: 0.8rem;
    border-radius: 3px; min-width: 30px; text-align: center;
}
.zone-z5 { background: #B8552C; }
.zone-z4 { background: #C97A2C; }
.zone-z3 { background: #C9B04A; }
.zone-z2 { background: #4A9B7C; }
.zone-z1 { background: #5681B8; }

.zone-row {
    border: 1px solid var(--rule); border-radius: var(--radius);
    margin-bottom: 0.6rem; overflow: hidden;
}
.zone-row-head {
    padding: 0.4rem 0.6rem; background: var(--paper-warm);
    border-bottom: 1px solid var(--rule);
}
.zone-row-fields {
    display: grid; grid-template-columns: repeat(11, 1fr);
    gap: 0.3rem; padding: 0.5rem;
}
.zone-row-fields .form-group label { font-size: 0.68rem; }
.zone-row-fields .form-group input {
    padding: 0.4rem 0.3rem; font-size: 16px; min-height: 38px;
    text-align: center; border: 1px solid var(--rule); border-radius: 3px;
    background: var(--white); color: var(--ink); width: 100%;
}
.zone-row-fields .form-group input:focus {
    outline: none; border-color: var(--gold); box-shadow: 0 0 0 2px rgba(184,149,74,0.15);
}

/* ========== SKJEMA LAYOUT ========== */
.skjema-layout { display: grid; grid-template-columns: 1fr; gap: 1.25rem; }
.skjema-layout.har-pdf { grid-template-columns: 1fr 1fr; }
.pdf-panel {
    position: sticky; top: 72px; height: calc(100vh - 88px);
    border: 1px solid var(--rule); border-radius: var(--radius);
    overflow: hidden; background: var(--ink);
}
.pdf-panel embed, .pdf-panel iframe { width: 100%; height: 100%; border: none; }
.pdf-panel-header {
    background: var(--ink); color: var(--paper);
    padding: 0.5rem 0.75rem; font-size: 0.8rem; font-weight: 600;
}
.submit-bar { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-top: 0.75rem; }

/* ========== BEKREFTELSE ========== */
.bekreft-card {
    background: var(--white); border: 1px solid var(--rule);
    border-left: 4px solid var(--success); border-radius: var(--radius);
    padding: 1.5rem; margin-bottom: 1.25rem;
}
.bekreft-card h2 { color: var(--success); margin-bottom: 0.4rem; }
.bekreft-info {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem; margin: 1.25rem 0; padding: 0.75rem;
    background: var(--paper-warm); border-radius: var(--radius);
}
.bekreft-info dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gold-deep); font-weight: 700; }
.bekreft-info dd { font-size: 0.95rem; font-weight: 600; color: var(--ink); }
.download-links { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1.25rem; }
.download-links .btn { flex: 1 1 0; min-width: 160px; }
.download-sub { margin-top: 0.75rem; }
.download-sub a { font-size: 0.82rem; color: var(--ink-soft); }

/* ========== ARKIV CARDS (mobile) ========== */
.arkiv-card { padding: 1rem; }
.arkiv-card-head { margin-bottom: 0.75rem; }
.arkiv-card-name { font-size: 1.05rem; font-weight: 700; color: var(--ink); }
.arkiv-card-meta { font-size: 0.85rem; color: var(--gold-deep); }
.arkiv-card-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* ========== LOGIN ========== */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; min-height: 100dvh; padding: 1rem;
    background: linear-gradient(180deg, var(--ink) 0%, #1B1F26 100%);
}
.login-card {
    background: var(--white); border-radius: 10px;
    padding: 2.5rem 2rem; width: 100%; max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2); text-align: center;
}
.login-brand {
    font-size: 1.5rem; font-weight: 800; letter-spacing: 0.04em;
    color: var(--ink); display: flex; align-items: center;
    justify-content: center; gap: 0.6rem; margin-bottom: 0.25rem;
}
.login-logo { width: 40px; height: 40px; border-radius: 8px; }
.login-sub { font-size: 0.85rem; color: var(--ink-soft); margin-bottom: 1.5rem; }
.login-form { text-align: left; }
.login-form label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 0.3rem; }
.login-input {
    width: 100%; padding: 0.7rem; border: 1px solid var(--rule);
    border-radius: var(--radius); font-size: 20px; text-align: center;
    letter-spacing: 0.3em; margin-bottom: 1rem; min-height: 52px;
    background: var(--paper-warm); color: var(--ink);
}
.login-input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(184,149,74,0.2); }
.login-locked { padding: 1.5rem 0; color: var(--danger); }
.login-locked p { margin-bottom: 0.4rem; }

/* ========== EMPTY/MISC ========== */
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--ink-soft); }
.empty-state p { font-size: 0.95rem; margin-bottom: 0.5rem; }
.footer {
    text-align: center; padding: 1.25rem; font-size: 0.8rem;
    color: var(--ink-soft); border-top: 1px solid var(--rule); margin-top: auto;
}
.confirm-form { display: inline; }
.badge {
    display: inline-block; padding: 0.15rem 0.5rem; border-radius: 3px;
    font-size: 0.75rem; font-weight: 700;
}
.badge-pending { background: rgba(184,149,74,0.15); color: var(--gold-deep); }
.badge-done { background: var(--success-bg); color: var(--success); }

.desktop-only { display: block; }
.mobile-only { display: none; }

/* ========== MOBILE ========== */
@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: block !important; }

    h1 { font-size: 1.35rem; }
    .subtitle { font-size: 0.88rem; margin-bottom: 1rem; }
    .container, .container-wide { padding: 1rem; }
    .grid-2 { grid-template-columns: 1fr; }
    .skjema-layout.har-pdf { grid-template-columns: 1fr; }
    .pdf-panel { position: static; height: 60vh; margin-bottom: 1rem; order: -1; }
    .card { padding: 1rem; margin-bottom: 1rem; }

    /* Hamburger */
    .nav { padding: 0 1rem; }
    .nav-toggle {
        display: flex; flex-direction: column; justify-content: center;
        gap: 5px; width: 32px; height: 32px;
        background: none; border: none; cursor: pointer; padding: 4px;
        -webkit-tap-highlight-color: transparent;
    }
    .nav-toggle span {
        display: block; width: 22px; height: 2px;
        background: var(--paper); border-radius: 1px;
        transition: transform 0.2s, opacity 0.2s;
    }
    .nav-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    .nav-toggle.open span:nth-child(2) { opacity: 0; }
    .nav-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
    .nav-links {
        display: none; position: absolute; top: 56px; left: 0; right: 0;
        background: var(--ink); flex-direction: column;
        padding: 0.5rem 1rem 1rem;
        border-top: 1px solid rgba(250,248,243,0.1);
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    }
    .nav-links.open { display: flex; }
    .nav-links a { padding: 0.7rem 0; font-size: 1rem; border-bottom: 1px solid rgba(250,248,243,0.06); }
    .nav-links a:last-child { border-bottom: none; }

    /* Pending */
    .pending-item { flex-wrap: wrap; }
    .pending-actions { width: 100%; margin-top: 0.4rem; }

    /* Forms */
    .form-grid { grid-template-columns: 1fr 1fr; }
    .form-grid-narrow { grid-template-columns: 1fr 1fr; }

    /* Zone rows -> card-like */
    .zone-row-fields { grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }

    /* Buttons */
    .download-links { flex-direction: column; }
    .download-links .btn { width: 100%; }
    .submit-bar { flex-direction: column; }
    .submit-bar .btn { width: 100%; }
    .bekreft-info { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 400px) {
    .form-grid { grid-template-columns: 1fr; }
    .form-grid-narrow { grid-template-columns: 1fr 1fr; }
    .zone-row-fields { grid-template-columns: repeat(2, 1fr); }
    .bekreft-info { grid-template-columns: 1fr; }
}

/* ── AI sparring (chat) ────────────────────────────────── */
.chat-messages {
    display: flex; flex-direction: column; gap: 0.6rem;
    max-height: 460px; overflow-y: auto; padding: 0.25rem; margin-bottom: 0.75rem;
}
.chat-messages:empty { display: none; }
.chat-msg { display: flex; flex-direction: column; max-width: 92%; }
.chat-user { align-self: flex-end; align-items: flex-end; }
.chat-assistant { align-self: flex-start; align-items: flex-start; }
.chat-bubble {
    padding: 0.6rem 0.8rem; border-radius: var(--radius);
    font-size: 0.9rem; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word;
}
.chat-user .chat-bubble {
    background: var(--ink); color: var(--paper); border-bottom-right-radius: 2px;
}
.chat-assistant .chat-bubble {
    background: var(--paper-warm); color: var(--ink);
    border: 1px solid var(--rule); border-bottom-left-radius: 2px;
}
.chat-assistant .btn-bruk { margin-top: 0.35rem; }
.chat-input-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.chat-input-row textarea {
    flex: 1; padding: 0.6rem; border: 1px solid var(--rule); border-radius: 4px;
    resize: vertical; font-family: inherit; font-size: 16px; min-height: 44px;
    background: var(--white); color: var(--ink);
}
.chat-input-row textarea:focus {
    outline: none; border-color: var(--gold); box-shadow: 0 0 0 2px rgba(184,149,74,0.15);
}
