:root {
    --kj-blue: #005CA8;
    --kj-blue-hover: #004a87;
    --kj-accent: #00a39b;
    --kj-gray-bg: #f4f6f8;
    --kj-border: #dfe3e8;
    --kj-text: #1a1a1a;
    --kj-text-light: #595959;
    --white: #ffffff;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --header-height: 64px;
}

/* FAB Button - Global Style (moved to top for priority) */
.fab-button {
    position: fixed !important;
    bottom: 24px !important;
    right: 24px !important;
    width: 56px !important;
    height: 56px !important;
    border-radius: 50% !important;
    background-color: var(--kj-blue) !important;
    color: white !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
    font-size: 2rem;
    text-decoration: none !important;
    z-index: 9999 !important;
    border: none !important;
    cursor: pointer !important;
    transition: transform 0.2s, background-color 0.2s;
}

.fab-button svg {
    display: block;
    margin: auto;
}

.fab-button:hover {
    background-color: var(--kj-blue-hover) !important;
    transform: scale(1.05);
}

.fab-button:active {
    transform: scale(0.95);
}

/* --- Base & Typography --- */
html {
    box-sizing: border-box;
    font-size: 16px;
}

*,
*:before,
*:after {
    box-sizing: inherit;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--kj-gray-bg);
    color: var(--kj-text);
    margin: 0;
    padding-top: var(--header-height);
    /* Space for fixed header */
    line-height: 1.5;
}

h1,
h2,
h3 {
    margin-top: 0;
    color: var(--kj-blue);
    font-weight: 600;
}

a {
    text-decoration: none;
    color: inherit;
}

/* --- Navigation Bar (Desktop) --- */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--header-height);
    background: var(--white);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1000;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--kj-blue);
}

.navbar-logo {
    height: 40px;
}

.navbar-menu {
    display: flex;
    gap: 8px;
    align-items: center;
}

.nav-link {
    padding: 8px 16px;
    border-radius: var(--radius);
    color: var(--kj-text-light);
    font-weight: 500;
    transition: all 0.2s;
}

.nav-link:hover,
.nav-link.active {
    background-color: #f0f4f8;
    color: var(--kj-blue);
}

/* Dropdown */
.nav-item-dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--white);
    border: 1px solid var(--kj-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 220px;
    display: none;
    flex-direction: column;
    padding: 8px 0;
    margin-top: 8px;
}

.nav-item-dropdown:hover .dropdown-menu {
    display: flex;
}

.dropdown-item {
    padding: 10px 16px;
    font-size: 0.95rem;
    color: var(--kj-text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.dropdown-item:hover {
    background-color: #f0f4f8;
    color: var(--kj-blue);
}

.dropdown-divider {
    height: 1px;
    background-color: var(--kj-border);
    margin: 4px 0;
}

.admin-badge {
    background: #eee;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    margin-left: auto;
}

/* --- Mobile Toggle --- */
.navbar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--kj-text);
    cursor: pointer;
    padding: 8px;
    /* Increased touch target */
}

/* --- Mobile Drawer (Off-Canvas) --- */
.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.drawer {
    position: fixed;
    top: 0;
    right: -280px;
    /* Hidden */
    width: 280px;
    height: 100%;
    background: var(--white);
    z-index: 1002;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    display: flex;
    flex-direction: column;
}

.drawer.open {
    right: 0;
}

.drawer-overlay.open {
    opacity: 1;
    visibility: visible;
}

.drawer-header {
    padding: 16px;
    border-bottom: 1px solid var(--kj-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 1.1rem;
}

.drawer-content {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.drawer-link {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-weight: 500;
    display: block;
}

.drawer-link:hover {
    background-color: #f0f4f8;
    color: var(--kj-blue);
}

.drawer-section-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: #888;
    margin: 16px 0 4px 16px;
    letter-spacing: 0.5px;
}

/* --- Layout Content --- */
.app-shell {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 16px 96px 16px;
    /* Extra bottom padding for FAB */
}

.app-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--kj-border);
}

/* --- Components --- */
.table-responsive {
    overflow-x: auto;
    border: 1px solid var(--kj-border);
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

th,
td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--kj-border);
    text-align: left;
}

th {
    background-color: #f9fafb;
    font-weight: 600;
    color: var(--kj-text-light);
}

tr:last-child td {
    border-bottom: none;
}

/* Buttons */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    background-color: var(--kj-blue);
    color: var(--white);
    border-radius: var(--radius);
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.95rem;
    text-align: center;
    line-height: 1;
    margin-right: 8px;
    min-height: 44px;
    /* Touch target size */
}

.button:last-child {
    margin-right: 0;
}

.button:hover {
    background-color: var(--kj-blue-hover);
}

.button-primary {
    background-color: var(--kj-blue);
}

.button-danger {
    background-color: #dc2626;
}

.button-danger:hover {
    background-color: #b91c1c;
}

.button-outline {
    background-color: transparent;
    border: 1px solid var(--kj-border);
    color: var(--kj-text);
}

.button-outline:hover {
    border-color: var(--kj-blue);
    color: var(--kj-blue);
    background-color: white;
}

.button-small {
    padding: 6px 12px;
    font-size: 0.85rem;
    min-height: 32px;
    /* Smaller for desktop bars, but still tappable */
}

.button-edit {
    background-color: #f59e0b;
    /* Orange */
    color: white;
    border: none;
}

.button-edit:hover {
    background-color: #d97706;
}

/* Form Styles */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 12px 12px;
    /* Larger padding */
    border: 1px solid var(--kj-border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s;
    background: var(--white);
    min-height: 44px;
    /* Touch friendly */
}

/* Hide spin buttons for Start Page input & Discount */
#discount-input::-webkit-outer-spin-button,
#discount-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#discount-input {
    -moz-appearance: textfield;
    appearance: textfield;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--kj-blue);
    box-shadow: 0 0 0 3px rgba(0, 92, 168, 0.1);
}

.success {
    color: #059669;
    background: #ecfdf5;
    padding: 12px;
    border-radius: 6px;
    border: 1px solid #a7f3d0;
}

.error {
    color: #dc2626;
    background: #fef2f2;
    padding: 12px;
    border-radius: 6px;
    border: 1px solid #fecaca;
}

/* --- Responsive Breakpoints --- */
@media (max-width: 920px) {
    .navbar-menu {
        display: none;
    }

    .navbar-toggle {
        display: block;
    }

    .form-grid,
    .form-grid-small {
        grid-template-columns: 1fr;
    }

    .app-card {
        padding: 16px;
        /* Less padding on mobile */
    }

    .app-shell {
        padding: 16px 8px;
        /* Less padding on mobile shell */
    }

    /* Mobile Text & Spacing Optimization */
    h1,
    h2,
    h3,
    p {
        text-align: center;
    }

    .form-col>label,
    form label {
        display: block;
        text-align: center;
        font-size: 1.05rem;
        margin-bottom: 12px;
    }

    input,
    select,
    textarea {
        text-align: center;
        font-size: 1.1rem !important;
        /* Larger font for mobile */
        padding: 14px 16px;
        /* More padding */
        margin-bottom: 24px;
        /* More vertical space */
    }

    .button {
        width: 100%;
        margin-right: 0;
        margin-bottom: 16px;
        padding: 14px;
        font-size: 1.05rem;
        justify-content: center;
    }

    /* Links in headers or lists */
    .app-card a:not(.button) {
        display: inline-block;
        padding: 5px 0;
        font-size: 1.05rem;
        /* Ensure links are distinct */
        color: var(--kj-blue);
        text-decoration: underline;
        text-underline-offset: 4px;
    }

    /* Hide checkboxes on mobile (not needed for simple view) */
    .check-col {
        display: none !important;
    }
}

/* --- Mobile Friendly Tables ("Card View") --- */
@media (max-width: 920px) {

    /* Force table to not behave like a table anymore */
    .table-responsive table,
    .table-responsive thead,
    .table-responsive tbody,
    .table-responsive th,
    .table-responsive td,
    .table-responsive tr {
        display: block;
    }

    /* Hide table headers (but not display: none;, for accessibility) */
    .table-responsive thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .table-responsive tr {
        border: 1px solid var(--kj-border);
        margin-bottom: 16px;
        border-radius: var(--radius);
        background: white;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    }

    .table-responsive td {
        /* Behave like a "row" */
        border: none;
        border-bottom: 1px solid #f1f5f9;
        position: relative;
        padding-left: 45%;
        padding-top: 10px;
        padding-bottom: 10px;
        text-align: right;
        min-height: 40px;
    }

    .table-responsive td:last-child {
        border-bottom: none;
    }

    .table-responsive td:before {
        /* Now like a table header */
        position: absolute;
        /* Top/left values mimic padding */
        top: 10px;
        left: 12px;
        width: 40%;
        white-space: nowrap;
        text-align: left;
        font-weight: 600;
        color: var(--kj-text-light);
        content: attr(data-label);
    }

    /* Specific overrides for certain columns content */
    .table-responsive td .button {
        width: 100%;
        margin: 4px 0;
    }

    /* Exceptions: if td content is empty or should be full width */
    .table-responsive td.full-width {
        padding-left: 12px;
        text-align: left;
    }

    .table-responsive td.full-width:before {
        display: none;
    }
}


/* --- Restored Utility Classes --- */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 16px;
}

.responsive-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

@media (max-width: 920px) {
    .responsive-grid {
        grid-template-columns: 1fr;
    }
}

.form-grid-small {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.form-col>label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
}

/* Drop Zones */
#drop-zone,
#quelle-dropzone {
    border: 2px dashed var(--kj-blue);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    background-color: #f0f7ff;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 16px;
}

@media (max-width: 920px) {

    #drop-zone,
    #quelle-dropzone {
        display: none;
    }
}

#drop-zone:hover,
#quelle-dropzone:hover {
    background-color: #e0efff;
    border-color: var(--kj-blue-hover);
}

/* Category Colors */
td.kat-2-schicht {
    background-color: #e6f5ff;
}

td.kat-3-schicht {
    background-color: #fff3e0;
}

td.kat-default {
    background-color: transparent;
}

/* Cluster Hints */
.cluster-hint {
    background-color: #f0fdf4;
    border-left: 4px solid #22c55e;
    padding: 12px 16px;
    margin: 16px 0;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 0.95rem;
}

.cluster-hint ul {
    margin: 8px 0 0 0;
    padding-left: 20px;
}

/* Admin Badge & Orientation */
.admin-badge {
    background-color: #f3f4f6;
    color: #4b5563;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.orientation-hint {
    display: none;
}

@media (max-width: 920px) {
    .hide-mobile-text span {
        display: none !important;
    }

    .hide-mobile {
        display: none !important;
    }

    .mobile-filter-toggle {
        display: flex !important;
    }
}

/* --- Import Wizard & Documentation --- */

/* Documentation Guide */
.doc-container {
    max-width: 900px;
    margin: 0 auto;
    background: var(--white);
    padding: 24px;
    /* Reduced for mobile */
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.doc-header {
    margin-bottom: 40px;
    text-align: center;
    border-bottom: 1px solid var(--kj-border);
    padding-bottom: 24px;
}

.doc-section {
    margin-bottom: 48px;
}

.doc-section h2 {
    font-size: 1.5rem;
    color: var(--kj-blue);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 2px solid #f1f5f9;
    padding-bottom: 8px;
}

.doc-section h2 .step-num {
    background: var(--kj-blue);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.doc-content {
    padding-left: 16px;
    /* reduced */
    color: var(--kj-text-light);
    line-height: 1.7;
}

.doc-tip {
    background: #f0f9ff;
    border-left: 4px solid var(--kj-blue);
    padding: 16px 24px;
    border-radius: 0 var(--radius) var(--radius) 0;
    margin-top: 16px;
    font-size: 0.95rem;
}

.doc-warning {
    background: #fef2f2;
    border-left: 4px solid #dc2626;
    padding: 16px 24px;
    border-radius: 0 var(--radius) var(--radius) 0;
    margin-top: 16px;
    font-size: 0.95rem;
    color: #991b1b;
}

/* Import Wizard UI */
.import-shell {
    max-width: 900px;
    margin: 0 auto;
}

.import-card {
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.upload-area {
    border: 2px dashed #cbd5e1;
    border-radius: 16px;
    padding: 40px 20px;
    text-align: center;
    transition: all 0.2s;
    background: #f8fafc;
    cursor: pointer;
    position: relative;
}

.mapping-container {
    border: 1px solid var(--kj-border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    background: white;
    margin: 24px 0;
}

.mapping-table {
    display: table;
    /* Force mapping table to stay table? Or use scroll? */
}

/* Exception for Mapping Table: Keep it scrollable because columns are dynamic and weird to "cardify" */
.mapping-container .table-responsive table {
    display: table;
}

.mapping-container .table-responsive thead {
    display: table-header-group;
}

.mapping-container .table-responsive tbody {
    display: table-row-group;
}

.mapping-container .table-responsive tr {
    display: table-row;
}

.mapping-container .table-responsive td,
.mapping-container .table-responsive th {
    display: table-cell;
    /* End of media query */

    /* Mobile text alignment for form columns */
    @media (max-width: 920px) {

        .form-col,
        .form-col-small {
            text-align: center;
        }

        /* Ensure small text is also centered */
        .form-col small,
        .form-col-small small {
            display: block;
            text-align: center;
        }

        /* Stack input group rows on mobile */
        .input-group-row {
            flex-direction: column;
        }
    }

    /* Input Group Row (for Format inputs) */
    .input-group-row {
        display: flex;
        gap: 8px;
        width: 100%;
    }

    .input-group-row input {
        flex: 1;
        min-width: 0;
        /* allows shrinking */
    }
}