/* ===== GENERELL RESET & BODY ===== */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    background: #f4f4f4;
    color: #333;
    line-height: 1.6;
}

/* ===== CONTAINER ===== */
.container {
    background: white;
    padding: 20px;
    border-radius: 5px;
    margin: 20px auto;
    max-width: 1600px; /* Holder tabellen innenfor grenser */
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

/* ===== HEADER & NAV ===== */
/* (Dine eksisterende stiler beholdes her, kun oppsummert for kontekst) */
nav { background: #333; width: 100%; position: relative;}

.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background-color: #2c3e50;
    color: white;
    flex-wrap: wrap;
}
.header-right {
    display: flex;
    flex-direction: column; 
    align-items: flex-end;
    gap: 5px;
    min-width: 0;
    justify-content: center;
}

.rudi-title { font-size: 1.6em; font-weight: bold; letter-spacing: 2px; }
.rudi-slogan { font-size: 0.85em; opacity: 0.8; margin: 2px 0 0 0; font-style: italic; }
.nav-links { display: flex; gap: 15px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.nav-links a { color: white; text-decoration: none; padding: 5px 0; }
.nav-links a:hover { text-decoration: underline; }

/* ===== DROPDOWN ===== */
.dropdown { position: relative; display: inline-block; }
.dropdown-toggle { cursor: pointer; color: white !important; padding: 5px 0; }
.dropdown-toggle::after { content: " ▾"; font-size: 0.8em; margin-left: 4px; }
.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background-color: #ffffff;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    border: 1px solid #ccc;
    border-radius: 4px;
    min-width: 220px;
    z-index: 1000;
}
.dropdown-menu.show { display: block !important; }
.dropdown-menu a { display: block; padding: 10px 15px; color: #333; border-bottom: 1px solid #eee; }
.dropdown-menu a:hover { background-color: #f0f0f0; color: #007bff; }

/* ===== KNAPPER ===== */
.btn {
    display: inline-block;
    padding: 6px 12px;
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
    text-decoration: none !important;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    background-color: #007bff;
    color: white;
}
.btn:hover { background-color: #0056b3; transform: translateY(-1px); }
.btn-success { background-color: #28a745; }
.btn-success:hover { background-color: #218838; }
.btn-primary { background-color: #007bff; }
.btn-danger { background-color: #dc3545; }
.btn-danger:hover { background-color: #c82333; }
.btn-sm { padding: 4px 8px; font-size: 0.85rem; }
.btn-warning { background-color: #eca200; }
.btn-warning:hover { background-color: #d18f02; }

/* ===== TABELL STILER (OPPDATERT) ===== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 15px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-size: 0.95rem;
    min-width: 900px; /* Sikrer at tabellen ikke krymper for mye på små skjermer */
}

table th, table td {
    padding: 12px 10px;
    border: 1px solid #dee2e6;
    text-align: left;
    vertical-align: middle;
    word-wrap: break-word; /* Hindrer lange ord i å ødelegge layout */
}

table th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #495057;
    white-space: nowrap; /* Overskrifter brytes ikke */
}

table tbody tr:nth-child(even) { background-color: #f9f9f9; }
table tbody tr:hover { background-color: #f1f1f1; }

/* Kolonnebredder (Justert for 10 kolonner) */
/* 1: Org (kun SA), 2: DMR, 3: Navn, 4: Fabrikat, 5: Modell, 6: S/N, 7: Kat, 8: Status, 9: Endret, 10: Hdl */
table th:nth-child(1) { width: 12%; } /* Organisasjon */
table th:nth-child(2) { width: 8%; }  /* DMR ID */
table th:nth-child(3) { width: 18%; } /* Navn */
table th:nth-child(4) { width: 12%; } /* Fabrikat */
table th:nth-child(5) { width: 12%; } /* Modell */
table th:nth-child(6) { width: 12%; } /* Serie nr */
table th:nth-child(7) { width: 10%; } /* Kategori */
table th:nth-child(8) { width: 8%; }  /* Status */
table th:nth-child(9) { width: 10%; } /* Sist endret */
table th:nth-child(10) { width: 8%; } /* Handlinger */

/* Status Badges */
.badge {
    display: inline-block;
    padding: 4px 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: white;
    text-align: center;
    min-width: 60px;
}
.status-tilgjengelig { background-color: #28a745; }
.status-reservert { background-color: #ffc107; color: #333; }
.status-i-bruk { background-color: #17a2b8; }
.status-vedlikehold { background-color: #dc3545; }

/* Handlinger-kolonnen */
.action-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    justify-content: flex-start;
}

/* Tekst hjelpere */
.text-center { text-align: center; }
.text-muted { color: #6c757d; }
.text-secondary { color: #6c757d; font-size: 0.85rem; }
.fw-bold { font-weight: 700; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }

/* ===== FILTER PANEL ===== */
.filter-panel {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    padding: 15px;
    margin-bottom: 20px;
    display: flex;
    gap: 15px;
    align-items: flex-end;
    flex-wrap: wrap;
}
.filter-group { display: flex; flex-direction: column; gap: 5px; }
.filter-group label { font-size: 0.85em; font-weight: bold; color: #495057; }
.filter-select, .filter-text {
    padding: 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
}
.filter-select { min-width: 150px; }
.filter-text { min-width: 200px; }
.clear-btn { background: #6c757d; color: white;}
.clear-btn:hover { background: #5a6268; }

/* ===== SORTERING ===== */
th.sortable { cursor: pointer; user-select: none; position: relative; }
th.sortable:hover { background-color: #e9ecef; }
th.sortable::after {
    content: '⇅'; position: absolute; right: 8px; opacity: 0.3; font-size: 0.8em; top: 50%; transform: translateY(-50%);
}
th.sort-asc::after { content: '↑'; opacity: 1; }
th.sort-desc::after { content: '↓'; opacity: 1; }

/* ===== FORMULARER (Modal & Input) ===== */
/* Generell input-styling (UTEN width: 100%) */
input[type="text"], input[type="email"], input[type="password"], select, textarea {
    padding: 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
}

/* Width: 100% KUN innenfor form-group (modaler) */
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group select,
.form-group textarea {
    width: 100%;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0,123,255,0.25);
}

/* ===== MODALER ===== */
.modal {
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0; 
    top: 0; 
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgba(0,0,0,0.5); 
}
.modal-content {
    background-color: #fefefe;
    margin: 5% auto; 
    padding: 20px; 
    border: 1px solid #888; 
    width: 600px; 
    border-radius: 8px; 
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.modal-header {
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 15px; 
    border-bottom: 1px solid #eee; 
    padding-bottom: 10px;
}
.modal-footer {
    text-align: right; 
    margin-top: 20px;
}
.close {
    color: #aaa; 
    font-size: 28px; 
    font-weight: bold; 
    cursor: pointer;
}
.close:hover { 
    color: black; 
}

/* ===== SKJEMA-GRUNPPER (Modal) ===== */
.form-group { 
    margin-bottom: 15px; 
}
.form-row { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 15px; 
    margin-bottom: 15px; 
}
.form-group label { 
    font-weight: bold; 
    display: block; 
    margin-bottom: 5px; 
}
.form-group input, 
.form-group select { 
    width: 100%; 
    padding: 8px; 
    border: 1px solid #ced4da; 
    border-radius: 4px; 
    box-sizing: border-box;
}

/* ===== ALERT-MELDINGER ===== */
.alert { 
    padding: 15px; 
    margin-bottom: 20px; 
    border-radius: 4px; 
}
.alert-success { 
    background-color: #d4edda; 
    color: #155724; 
    border: 1px solid #c3e6cb; 
}
.alert-danger { 
    background-color: #f8d7da; 
    color: #721c24; 
    border: 1px solid #f5c6cb; 
}

/* Grep-ikon for sone-drag */
.zone-drag-handle {
    opacity: 0.4;
    transition: opacity 0.2s ease;
}
.zone-drag-handle:hover {
    opacity: 1;
}
.zone-drag-handle:active {
    cursor: grabbing;
}

/* Synlig grep-ikon på touch-enheter */
@media (hover: none) and (pointer: coarse) {
    .zone-drag-handle {
        opacity: 0.7;
    }
}

/* Ghost-stiler for sone-drag */
.sortable-zone-ghost {
    opacity: 0.3;
    background: #e8f0fe;
    border: 2px dashed #1a73e8;
}
.sortable-zone-drag {
    opacity: 1;
    background: #fff;
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

/* --- MOBIL FIX: Tving touch-action på grep-ikonet --- */

/* Grep-ikon for soner */
.zone-drag-handle {
    cursor: grab;
    touch-action: none; /* VIKTIG: Hindrer browseren i å scrollere når man trykker her */
    -webkit-touch-callout: none; /* Hindrer kontekstmeny på iOS */
    user-select: none;
    -webkit-user-select: none;
    z-index: 100; /* Sørg for det er over alt annet */
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px; /* Gi det litt bredde for lett touch */
    height: 30px;
    background: rgba(0,0,0,0.05); /* Litt bakgrunn for å vise området */
    border-radius: 4px;
}

.zone-drag-handle:active {
    cursor: grabbing;
    opacity: 0.8;
    background: rgba(0,0,0,0.1);
}

/* Grep-ikon for kanaler */
.drag-handle {
    cursor: grab;
    touch-action: none; /* VIKTIG */
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
    z-index: 100;
    position: relative;
}

.drag-handle:active {
    cursor: grabbing;
}

/* Sikre at resten av headeren ikke starter drag */
.zone-header {
    touch-action: pan-y; /* Tillater kun vertikal scrolling på hele headeren */
    user-select: none;
    -webkit-user-select: none;
}

/* Sikre at toggle-knappen ikke interfererer */
.zone-toggle {
    touch-action: manipulation; /* Tillater klikk, hindrer dobbelttrykk-zoom */
    z-index: 101; /* Høyere enn drag-handle for å sikre klikk */
    position: relative;
    cursor: pointer;
}