/**
 * MASSO - Municipal Assessor's Office Support System
 * Main stylesheet — enhanced UI.
 */

:root {
    --color-primary: #0f7e58;
    --color-primary-hover: #0c6a4b;
    --color-primary-light: #d1fae5;
    --color-warning: #f59e0b;
    --color-warning-bg: #fef3c7;
    --color-success: #22c55e;
    --color-success-bg: #dcfce7;
    --color-error: #ef4444;
    --color-error-bg: #fee2e2;
    --color-danger: #ef4444;
    --color-danger-hover: #b91c1c;
    --color-surface: #ffffff;
    --color-background: #f4f6fb;
    --color-border: #e2e8f0;
    --color-text: #0f172a;
    --color-text-muted: #475569;
    --radius: 10px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow-hover: 0 10px 25px -5px rgba(15, 23, 42, 0.12);
    --sidebar-width: 260px;
    --font-sans: 'DM Sans', 'Segoe UI', system-ui, sans-serif;
    --transition: 0.2s ease;
}

/* --- Documents table containment fixes (overrides) --- */
/* Keep the table contained inside the results card and allow internal scrolling when needed */
.results-section.card { overflow: hidden; }
.results-section.card .table-wrap { overflow-x: auto; padding: 0; }
.results-section.card .table-wrap table { width: 100%; box-sizing: border-box; }
.data-table.documents-table { border-collapse: separate; border-spacing: 0 10px; width: 100%; box-sizing: border-box; }
.data-table.documents-table tbody td { background-clip: padding-box; }
.data-table.documents-table td:first-child { width: 96px; min-width: 96px; }


/* Hide horizontal scrollbar visually on larger screens while keeping scrolling functional */
@media (min-width: 1100px) {
    .results-section.card .table-wrap {
        -ms-overflow-style: none; /* IE 10+ */
        scrollbar-width: none; /* Firefox */
    }
    .results-section.card .table-wrap::-webkit-scrollbar { display: none; height: 0; }
}


/* Dark mode */
body.dark-mode {
    --color-surface: #1e293b;
    --color-background: #0f172a;
    --color-border: #334155;
    --color-text: #f1f5f9;
    --color-text-muted: #94a3b8;
    --color-primary-light: #064e3b;
    --color-warning-bg: #78350f;
    --color-success-bg: #064e3b;
    --color-error-bg: #450a0a;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
}

body.dark-mode .sidebar { --sidebar-bg: #1e293b; --sidebar-border: #334155; }
body.dark-mode .card { background: var(--color-surface); border-color: var(--color-border); }
body.dark-mode .stat-card { background: var(--color-surface); border-color: var(--color-border); }
body.dark-mode .app-footer { background: var(--color-surface); border-color: var(--color-border); color: var(--color-text-muted); }
body.dark-mode .data-table th { background: var(--color-background); }
body.dark-mode .data-table tbody tr:nth-child(even) { background: rgba(255,255,255,0.03); }
body.dark-mode .data-table tbody tr:hover { background: var(--color-primary-light); }
body.dark-mode .theme-toggle { background: var(--color-border); color: var(--color-text); display: flex; align-items: center; justify-content: center; }
body.dark-mode .theme-toggle:hover { background: var(--color-primary); }
body.dark-mode .theme-toggle .material-icons { display: flex; align-items: center; justify-content: center; font-size: 1.2rem; line-height: 1; }

* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
    color: var(--color-text);
    margin: 0;
    padding: 0;
    background: var(--color-background);
    transition: background-color var(--transition), color var(--transition);
}

/* --- Login page --- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-background);
    padding: 2.5rem 1rem;
}

.login-box {
    width: 100%;
    max-width: 420px;
    padding: 2.5rem;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--color-border);
}

/* Ensure the login box is centered on smaller screens */
@media (max-width: 900px) {
    .login-page { justify-content: center; padding: 1rem; }
    .login-box { margin: 0; }
}

.login-box h1 {
    margin: 0 0 0.25rem 0;
    font-size: 1.85rem;
    font-weight: 700;
    text-align: center;
    color: var(--color-primary);
}

.login-box .tagline {
    margin: 0 0 1.5rem 0;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    text-align: center;
}

.login-form label {
    display: block;
    margin: 0 0 0.25rem 0;
    font-weight: 500;
}

.login-form input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}

.login-form input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

/* --- Messages --- */
.message {
    padding: 0.75rem;
    margin-bottom: 1rem;
    border-radius: 4px;
}

.message-error {
    background: var(--color-error-bg);
    color: var(--color-error);
    border: 1px solid #ffcdd2;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.55rem 1.2rem;
    font-size: 1rem;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.1s ease, box-shadow 0.15s ease, background-color 0.15s ease;
    box-shadow: 0 1px 3px rgba(15,23,42,0.08);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 18px rgba(15,23,42,0.14);
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    box-shadow: 0 6px 18px rgba(15,126,88,0.18);
}

.btn-primary:hover {
    background: var(--color-primary-hover);
}

.pagination-centered { display:flex; justify-content:center; gap:0.6rem; margin-top:0.75rem; }

.pagination-bottom-row {
    display: grid;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.pagination-actions {
    display: flex;
    justify-content: center;
    gap: 0.6rem;
}

.btn-large {
    padding: 0.75rem 1.25rem;
    font-size: 1.05rem;
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(37,99,235,0.12);
    transition: transform 0.18s cubic-bezier(.2,.9,.3,1), box-shadow 0.18s ease, opacity 0.18s ease;
}
.btn-large:active { transform: translateY(2px) scale(0.998); }
.btn-loading { opacity: 0.7; pointer-events: none; }

/* Spinner inside loading button */
.btn-large.btn-loading { position: relative; color: rgba(255,255,255,0.9); }
.btn-large.btn-loading::after {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: rgba(255,255,255,1);
    border-radius: 50%;
    animation: masso-spin 0.8s linear infinite;
}

/* Row insert animation */
@keyframes rowIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.row-animate { animation: rowIn 280ms ease both; }

.btn-secondary {
    background: #f5f7fb;
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: #eef2fb;
}

.btn-warning {
    background: var(--color-warning);
    color: #1f2937;
}

.btn-warning:hover {
    background: #d97706;
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}

.btn-danger:hover {
    background: var(--color-danger-hover);
}

.activity-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.92rem;
    font-weight: 600;
}

.activity-pill--success {
    color: var(--color-success);
}

.activity-pill--warning {
    color: var(--color-warning);
}

.activity-pill--danger {
    color: var(--color-danger);
}

.activity-pill--neutral {
    color: var(--color-text);
}

.activity-summary {
    font-size: 0.95rem;
    color: var(--color-text-muted);
    margin-bottom: 0.75rem;
}

/* Utility: full width button when needed */
.btn-block { display:block; width:100%; }

/* Keep login buttons full-width */
.login-box .btn-primary { width:100%; }

/* Make login button text centered when full-width */
.login-box .btn-primary { justify-content: center; }

/* Left-side illustration placeholder on login page */
.login-graphic {
    width: 420px;
    max-width: 45%;
    min-width: 260px;
    height: 420px;
    margin-right: 2rem;
    background: rgba(11,61,145,0.08);
    border-radius: 12px;
    box-shadow: 0 8px 18px rgba(15,23,42,0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    font-size: 1rem;
    border: 1px solid rgba(15,23,42,0.08);
    border-left: 4px solid var(--color-primary);
}

@media (max-width: 900px) {
    .login-graphic { display: none; }
}

/* Document actions (view page) base layout */
.document-actions { display:flex; gap:0.5rem 0.75rem; align-items:center; flex-wrap:wrap; margin-bottom:1rem; }

.btn-secondary:hover {
    background: #dadce0;
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}

.btn-danger:hover {
    background: var(--color-danger-hover);
}

/* --- App layout: sidebar + main --- */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

:root { --sidebar-bg: #ffffff; --sidebar-border: #e2e8f0; }
.sidebar {
    --sidebar-bg: #ffffff;
    --sidebar-border: #e2e8f0;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    box-shadow: 0 2px 14px rgba(15,23,42,0.05);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    padding: 1.25rem 1rem;
    color: var(--color-text);
    font-size: 0.95rem;
    transition: transform var(--transition), box-shadow var(--transition);
    display: flex;
    flex-direction: column;
    z-index: 120;
}
.sidebar .logo {
    font-weight: 700;
    font-size: 1.35rem;
    color: var(--color-primary);
    text-decoration: none;
    letter-spacing: -0.02em;
}
.sidebar .logo:hover { color: var(--color-primary-hover); opacity: 0.95; }

/* Brand: small inline logo + animated label */
.sidebar-brand .logo {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
}
.brand-logo {
    width: 28px;
    height: 28px;
    display: block;
    border-radius: 4px;
    object-fit: contain;
}

/* stronger selector to avoid accidental overrides by other rules */
.sidebar .sidebar-brand .logo > .brand-logo {
    width: 32px;
    height: 32px;
    max-width: 44px;
    object-fit: contain;
}
.brand-label {
    display: inline-block;
    font-weight: 700;
    font-size: 1.12rem;
    color: var(--color-primary);
    transform-origin: left center;
}

@keyframes brandSlideIn {
    0% { transform: translateX(-10px) skewX(-18deg); opacity: 0; }
    60% { transform: translateX(6px) skewX(6deg); opacity: 1; }
    100% { transform: translateX(0) skewX(0); opacity: 1; }
}
.brand-animate {
    animation: brandSlideIn 760ms cubic-bezier(.2,.9,.3,1) both;
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .brand-animate { animation: none; }
}

/* Mobile: adjust brand sizing and hide label on very small screens */
@media (max-width: 420px) {
    .sidebar-brand .logo { gap: 0.45rem; }
    .brand-logo { width: 26px; height: 26px; }
    /* show the label on narrow devices but keep it compact */
    .brand-label { display: inline-block; font-size: 0.95rem; font-weight: 700; color: var(--color-primary); }
}

@media (max-width: 900px) {
    /* Dark-mode friendly hamburger button: use color vars available at body scope */
    body.dark-mode .sidebar-toggle {
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        color: var(--color-text);
        box-shadow: 0 2px 8px rgba(0,0,0,0.45);
    }
    /* Ensure the three-line icon uses currentColor and is visible */
    .sidebar-toggle span { background: currentColor; }

    /* Tweak theme toggle sizing for better fit on iOS */
    .theme-toggle { display: inline-flex; align-items: center; justify-content: center; padding: 0; width:36px; height:36px; border-radius:8px; -webkit-appearance: none; appearance: none; }
    .theme-toggle .material-icons { font-size: 18px; line-height: 18px; display: inline-flex; align-items: center; justify-content: center; -webkit-font-smoothing: antialiased; transform: translateZ(0); }
    body.dark-mode .theme-toggle { background: transparent; border: 1px solid var(--color-border); color: var(--color-text); }
    body:not(.dark-mode) .theme-toggle { background: transparent; border: 1px solid transparent; color: var(--color-text-muted); }
}

/* Buttons/transitions */
.btn, button, input[type="submit"] {
    transition: background-color var(--transition), color var(--transition), transform var(--transition);
}
.btn:hover, button:hover, input[type="submit"]:hover { transform: translateY(-1px); }

/* Form controls */
input, select, textarea {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: inset 0 1px 2px rgba(15,23,42,0.06);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input:focus, select:focus, textarea:focus { box-shadow: 0 0 0 3px rgba(11,61,145,0.16); border-color: var(--color-primary); outline: none; }

/* Dark mode adjustments for better contrast */
body.dark-mode .quick-search { background: rgba(255,255,255,0.03); border-color: rgba(255,255,255,0.06); }
body.dark-mode input, body.dark-mode select, body.dark-mode textarea { background: #0b1220; color: var(--color-text); border-color: #1f2937; }
body.dark-mode .btn-primary { background: var(--color-primary); color: #fff; }
body.dark-mode .btn-secondary { background: rgba(255,255,255,0.03); color: var(--color-text); border-color: rgba(255,255,255,0.06); }
body.dark-mode .quick-search input::placeholder { color: rgba(255,255,255,0.45); }
.sidebar-toggle {
    display: none;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    border-radius: var(--radius-sm);
    -webkit-appearance: none;
    appearance: none;
}
.sidebar-toggle span { display: block; width: 18px; height: 2px; background: currentColor; border-radius: 1px; margin: 0 auto; transition: background 0.12s ease, transform 0.12s ease; }
/* prevent iOS tap highlight and ensure crisp rendering */
.sidebar-toggle, .theme-toggle { -webkit-tap-highlight-color: transparent; }
.sidebar-toggle span, .theme-toggle .material-icons { -webkit-font-smoothing: antialiased; -webkit-transform: translateZ(0); transform: translateZ(0); }
.quick-search {
    padding: 1rem 1.25rem;
    display: flex;
    gap: 0;
    align-items: center;
    background: var(--color-surface);
    margin: 1rem 1.25rem 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}
.quick-search input {
    flex: 1;
    min-width: 0;
    padding: 0.5rem 0.75rem;
    border: none;
    background: transparent;
    color: var(--color-text);
    font-size: 0.9rem;
}
.quick-search input::placeholder { color: var(--color-text-muted); }
.quick-search input:focus { outline: none; }
.quick-search-btn {
    padding: 0.5rem 0.75rem;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 1.1rem;
}
.quick-search-btn:hover { color: var(--color-text); }
.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    overflow-y: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar {
    width: 0;
    height: 0;
}
.sidebar-nav .sidebar-section-label {
    display: block;
    margin: 1rem 0 0.5rem;
    padding-left: 0.75rem;
    font-size: 0.74rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    font-weight: 700;
}
.sidebar-nav .nav-item,
.sidebar-nav button.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1rem;
    margin-bottom: 2px;
    color: var(--color-text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    transition: background var(--transition), color var(--transition);
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    cursor: pointer;
}
.sidebar-nav .nav-item:hover,
.sidebar-nav button.nav-item:hover {
    background: rgba(11,61,145,0.08);
    color: var(--color-text);
}
.sidebar-nav .nav-group {
    margin-bottom: 0.5rem;
}
.sidebar-nav .nav-group-toggle {
    justify-content: space-between;
}
.sidebar-nav .nav-group-arrow {
    margin-left: auto;
    transition: transform 0.2s ease;
}
.sidebar-nav .nav-group.open .nav-group-arrow {
    transform: rotate(90deg);
}
.sidebar-nav .nav-submenu {
    display: none;
    flex-direction: column;
    margin-top: 0.25rem;
    padding-left: 0.5rem;
}
.sidebar-nav .nav-group.open .nav-submenu {
    display: flex;
}
.sidebar-nav .nav-submenu .nav-item {
    padding-left: 2rem;
    background: transparent;
}
.sidebar-nav .nav-item .nav-icon { opacity: 0.8; font-size: 1rem; color: inherit; }
.sidebar-nav .nav-logout { color: var(--color-text-muted); margin-top: auto; }
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}
.user-block { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-weight: 600; color: var(--color-text); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 0.8rem; color: var(--color-text-muted); }
.theme-toggle {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(15,23,42,0.06);
    color: var(--color-text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    transition: background var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}
.theme-toggle:hover { background: rgba(15,23,42,0.1); }
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
    opacity: 0;
    transition: opacity var(--transition);
}
.sidebar-overlay.is-open { display: block; opacity: 1; }
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.top-bar {
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    min-height: 52px;
}
.top-bar-spacer { flex: 1; }
.flash {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    animation: flashIn 0.3s ease;
    transition: opacity 0.3s, transform 0.3s;
}
@keyframes flashIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.flash-success { background: var(--color-success-bg); color: var(--color-success); }
.flash-error { background: var(--color-error-bg); color: var(--color-error); }
.page-content {
    flex: 1;
    padding: 1.5rem 1.5rem 2rem;
    /* allow the page area to use full available width; individual pages center using .content-wrap */
    max-width: none;
    width: auto;
    margin: 0;
}

/* Search form modern styles */
.search-form.card {
    padding: 1rem 1.25rem;
    border-radius: 12px;
    box-shadow: var(--shadow);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
}
.search-form .form-row { display:flex; flex-wrap:wrap; gap:1rem; align-items:flex-end; }
.search-form .form-group { display:flex; flex-direction:column; min-width:140px; }
.search-form .search-row { align-items:center; gap:1rem; }
.search-form .form-group.form-group--lg { flex: 2 1 420px; min-width:320px; }
.search-form .form-group.form-group--sm { flex: 0 0 220px; max-width:240px; }

/* Standardize control heights and visual spacing */
.search-form input[type="search"],
.search-form input[list],
.search-form input[type="text"],
.search-form input[type="number"],
.search-form select,
.search-form datalist + input {
    height:44px;
    padding:0.6rem 0.9rem;
    border-radius:8px;
    font-size:0.95rem;
}
.search-input-wrap { position: relative; }
.search-input-wrap input[type="search"],
.search-input-wrap input[type="text"] {
    padding-right: 56px;
}
.search-input-wrap input[list] {
    padding-right: 56px;
}
.search-input-wrap .input-clear { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); border: none; background: transparent; display: inline-flex; align-items:center; justify-content:center; padding:6px; border-radius:6px; cursor:pointer; color: var(--color-text); }
.search-input-wrap.has-dropdown input[list] { padding-left: 40px; padding-right: 32px; }
.search-input-wrap.has-dropdown .input-clear { left: 10px; right: auto; }
.search-input-wrap .input-clear svg { width:18px; height:18px; stroke:currentColor; }
/* hide native clear button in WebKit */
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-form input::placeholder { color: var(--color-text-muted); }

/* quick-search removed */


.search-form .form-actions { margin-left:auto; display:flex; gap:.5rem; align-items:center; }
.search-form .form-actions .btn { height:44px; display:inline-flex; align-items:center; }
.search-form .form-actions .btn-primary { padding:0 1rem; }
.search-form .form-actions .btn-secondary { padding:0 0.9rem; }

/* Tweak datalist styling fallback */
input[list] { -webkit-appearance: textfield; appearance: textfield; }

/* When advanced search is open, stack the advanced fields above the action buttons */
.search-form .search-advanced {
    width: 100%;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.32s ease, opacity 0.22s ease, transform 0.25s ease;
    transform-origin: top left;
}
.search-form.advanced-open .search-advanced { order: 2; display: block !important; max-height: 360px; opacity: 1; transform: none; }
.search-form.advanced-open .form-actions { order: 3; width: 100%; justify-content: flex-end; margin-top: 0.5rem; }
.search-form.advanced-open #toggle-search-advanced { /* show as small collapse link */ padding: 0.375rem 0.6rem; font-size: 0.9rem; opacity: 0.9; }
.search-form .btn .btn-icon { width:18px; height:18px; display:inline-flex; align-items:center; justify-content:center; margin-right:8px; }

.search-form label { font-size:0.85rem; color:var(--color-text-muted); margin-bottom:0.35rem; }
.search-form input[type="text"], .search-form input[type="number"], .search-form select {
    padding:0.5rem 0.75rem; border:1px solid var(--color-border); border-radius:8px; background:transparent;
}
.search-form .search-advanced { border-radius:8px; border:1px solid var(--color-border); background:var(--color-surface); }

@media (max-width: 900px) {
    .search-form .form-row { flex-direction:column; }
    .search-form .form-group { width:100%; }
}
.app-footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 0.75rem 1.5rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-left: var(--sidebar-width);
    flex: 0 0 auto;
}
.footer-inner { max-width: 1200px; margin: 0 auto; display:flex; align-items:center; justify-content:center; }
.footer-inner .footer-content { color: var(--color-text-muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* --- Cards --- */
.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--color-border);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
}

.card h2 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-text);
}

/* --- Breadcrumb --- */
.breadcrumb {
    font-size: 0.9rem;
    margin-bottom: 1rem;
    color: var(--color-text-muted);
}

.breadcrumb a {
    color: var(--color-primary);
    text-decoration: none;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

/* --- Dashboard --- */
.dashboard-wrap {
    max-width: 1100px;
    margin: 0 auto;
}

.dashboard-wrap h1 {
    margin-bottom: 0.25rem;
    font-size: 1.5rem;
    font-weight: 700;
}

.welcome-text {
    margin: 0;
    color: var(--color-text-muted);
}

.dashboard-header { display:flex; align-items:center; justify-content:space-between; gap:1rem; margin-bottom:1rem; }

.stats-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-hover);
    border: 1px solid var(--color-border);
    padding: 0.85rem 1rem;
    min-width: 220px;
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:0.75rem;
}
.stat-icon {
    min-width: 48px;
    max-width: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.stat-icon-modern .material-icons {
    font-size: 2.6rem;
    color: var(--color-primary);
    background: none;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
}
.stat-card.stat-users .stat-icon-modern .material-icons {
    color: var(--color-success);
}

.stat-label {
    font-size: 0.95rem;
    color: var(--color-text-muted);
    display: block;
    font-weight: 500;
    letter-spacing: 0.01em;
}
.stat-value {
    display: block;
    font-size: 2.3rem;
    color: var(--color-primary);
    font-weight: 800;
    text-align: right;
    letter-spacing: -0.01em;
}
.stat-card .stat-text {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.1rem;
}

.stat-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-4px); }

/* Make stat cards clickable when rendered as anchors */
a.stat-card, .stat-card.stat-docs, .stat-card.stat-users { text-decoration: none; color: inherit; }
a.stat-card:focus { outline: none; box-shadow: 0 0 0 4px rgba(37,99,235,0.08); }

/* Slightly larger dashboard header */
.dashboard-wrap h1 { font-size: 1.75rem; }

/* Make recent items more compact and professional */
.recent-list li { display:flex; justify-content:space-between; align-items:center; gap:1rem; }
.recent-list .recent-meta { margin:0; text-align:right; }

/* Improve input/border contrast in light mode */
input, select, textarea { border-color: rgba(15,23,42,0.08); }
@media (prefers-color-scheme: light) {
    input, select, textarea { border-color: rgba(15,23,42,0.12); }
}

/* Dashboard charts */
.month-bars { width: 100%; height: 120px; display:block; }
.type-bars { display:flex; flex-direction:column; gap:0.5rem; }
.type-row { display:flex; gap:0.75rem; align-items:center; }
.type-title { flex: 0 0 220px; font-weight:600; color:var(--color-text); }
.type-code { color:var(--color-text-muted); font-weight:500; font-size:0.9rem; }
.type-bar-track { flex:1; background:var(--color-background); border-radius:6px; height:10px; overflow:hidden; border:1px solid var(--color-border); }
.type-bar-fill { height:100%; background: var(--color-primary); }
.type-bar-fill.warning { background: var(--color-warning); }
.type-bar-fill.danger { background: var(--color-danger); }
.type-count { width:56px; text-align:right; color:var(--color-text-muted); }

/* Button icons */
.btn .btn-icon { display:inline-flex; width:18px; height:18px; margin-right:8px; vertical-align:middle; }
.btn .btn-icon svg { width:18px; height:18px; fill:none; stroke:currentColor; }

.material-icons {
    font-family: 'Material Icons';
    font-weight: normal;
    font-style: normal;
    font-size: 18px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
}
/* ensure .btn-text retains spacing when icon present */
.btn .btn-text { display:inline-block; vertical-align:middle; }

.stat-card {
    background: #fff;
    border-radius: 1.1rem;
    box-shadow: 0 2px 12px 0 rgba(37,99,235,0.07);
    border: 1px solid #e5e7eb;
    padding: 1.1rem 1.5rem;
    min-width: 220px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.1rem;
    transition: box-shadow 0.18s, transform 0.18s;
}

.dashboard-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.dashboard-actions .btn-primary {
    width: auto;
}

.recent-card {
    margin-bottom: 0;
}

.recent-list {
    list-style: none;
    margin: 0 0 0.75rem 0;
    padding: 0;
}

.recent-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border);
}

.recent-list li:last-child {
    border-bottom: none;
}

.recent-list a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
}

.recent-list a:hover {
    text-decoration: underline;
}

.recent-meta {
    display: block;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-top: 0.2rem;
}

.recent-card p:last-child {
    margin: 0;
}

.recent-card p:last-child a {
    color: var(--color-primary);
    text-decoration: none;
}

.recent-card p:last-child a:hover {
    text-decoration: underline;
}

.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}
@media (max-width: 768px) {
    .charts-row { grid-template-columns: 1fr; }
}
.chart-card h2 { margin: 0 0 1rem 0; font-size: 1rem; }
.bar-chart { font-size: 0.9rem; }
.bar-row {
    display: grid;
    grid-template-columns: 80px 1fr 40px;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}
.bar-label { color: var(--color-text-muted); }
.bar-track {
    height: 8px;
    background: var(--color-border);
    border-radius: 4px;
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 4px;
    transition: width 0.3s ease;
}
.bar-value { text-align: right; font-weight: 600; color: var(--color-text-muted); }
.type-list { list-style: none; margin: 0; padding: 0; }
.type-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}
.type-list li:last-child { border-bottom: none; }
.type-name { color: var(--color-text); }
.type-count { font-weight: 600; color: var(--color-primary); }

.type-legend {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.9rem;
}
.type-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.type-legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}
.type-legend-count {
    margin-left: auto;
    color: var(--color-text-muted);
}

.empty-state {
    color: var(--color-text-muted);
    margin: 0.5rem 0;
}

.empty-state a {
    color: var(--color-primary);
    text-decoration: none;
}

.empty-state a:hover {
    text-decoration: underline;
}

/* --- Content wrap (shared) --- */
.content-wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding-left: 8px;
    padding-right: 8px;
}
.data-table th:nth-child(1), .data-table td:nth-child(1) { width: 96px; min-width: 96px; }

.content-wrap h1 {
    margin-bottom: 0.5rem;
}

.content-wrap h2 {
    font-size: 1.1rem;
    margin: 1.5rem 0 0.5rem 0;
}

/* --- Messages --- */
.message-success {
    background: var(--color-success-bg);
    color: var(--color-success);
    border: 1px solid #a5d6a7;
}

/* --- Forms (users page) --- */
.section-form,
.section-table {
    margin-top: 1rem;
}

.form-inline { display:flex; flex-direction:column; gap:1rem; }
.form-inline .form-row { display:grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; align-items: flex-start; }
.form-inline label,
.form-inline button { margin:0; }
.form-inline label { display:block; margin-bottom:0.25rem; }
.form-inline .form-actions { display:flex; align-items:flex-end; gap:0.75rem; }
.form-inline .form-actions .btn { margin-top: 0; }
.form-inline input,
.form-inline select { margin:0; }

.form-inline input,
.form-inline select {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    font-size: 1rem;
    background: var(--color-surface);
    box-shadow: inset 0 1px 2px rgba(15,23,42,0.06);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-inline input:focus,
.form-inline select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(11,61,145,0.16);
}

/* Tighter widths for the users form */
.section-form .form-inline label { min-width: 80px; }
.section-form .form-inline input[type="text"],
.section-form .form-inline input[type="password"] { width: 220px; }
.section-form .form-inline select { width: 140px; }

.form-inline .btn-primary {
    width: auto;
    margin-top: 0;
}

/* --- Upload form --- */
.upload-form .form-group {
    margin-bottom: 1rem;
}

.upload-form .form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    align-items: start;
}

.upload-form .form-row .form-group {
    width: 100%;
}

.upload-form .form-group--full {
    grid-column: 1 / -1;
}

.upload-form .advanced-group {
    border-top: 1px solid var(--color-border);
    padding-top: 0.75rem;
    margin-top: 1rem;
}

.upload-form .advanced-fields .form-row + .form-row {
    border-top: 1px solid var(--color-border);
    margin-top: 0.75rem;
    padding-top: 0.75rem;
}

.upload-form .form-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.upload-form .form-group input[type="text"],
.upload-form .form-group input[type="number"],
.upload-form .form-group input[type="file"],
.upload-form .form-group select {
    width: 100%;
    max-width: 400px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
}

/* Ensure clear-button helpers inside the upload form have enough padding */
.upload-form .form-group .search-input-wrap {
    position: relative;
    display: inline-flex;
    width: 100%;
    max-width: 400px;
}

.upload-form .form-group .search-input-wrap input {
    width: 100%;
    padding-right: 2.5rem;
    box-sizing: border-box;
}

.upload-form .form-group select {
    cursor: pointer;
}

.document-type-other {
    margin-top: 0.5rem;
    max-width: 400px;
}
.form-hint {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin: 0.5rem 0 0.25rem 0;
}

.upload-form .form-group input:focus,
.upload-form .form-group select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.upload-form .form-group input[type="file"] {
    padding: 0.35rem 0;
}

.upload-form .required {
    color: var(--color-error);
}

.form-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 0.75rem;
}

.form-actions .btn-primary {
    width: auto;
}

/* --- Data table --- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
}

/* Use fixed table layout so column widths are predictable and avoid horizontal overflow
   Define reasonable column widths (adjustable) so the action buttons fit without causing swipe */
.data-table {
    /* prefer automatic layout so columns size to content and browser can distribute space */
    table-layout: auto;
}
/* allow sensible wrapping for long text but keep most cells compact */
.data-table th, .data-table td { vertical-align: middle; }
/* No explicit per-column min-widths — allow browser to distribute width and wrap text as needed */
/* Keep the thumbnail and actions columns compact via their content and padding rather than fixed widths */

/* Allow table cells to wrap at word boundaries; avoid breaking words mid-word */
.data-table th, .data-table td { white-space: normal; word-break: normal; overflow-wrap: break-word; }

.data-table th,
.data-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border: 1px solid #e0e0e0;
}

/* Slightly tighter padding to fit more columns */
.data-table th,
.data-table td { padding: 0.45rem 0.6rem; }

.data-table th {
    background: var(--color-background);
    font-weight: 600;
    font-size: 0.9rem;
}

.data-table tbody tr:hover {
    background: var(--color-primary-light);
}

.data-table tbody tr:nth-child(even) {
    background: #fafbfc;
}

.data-table tbody tr:nth-child(even):hover {
    background: var(--color-primary-light);
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 0.5rem;
}

.table-responsive .data-table {
    min-width: 720px;
}

@media (max-width: 900px) {
    .data-table th, .data-table td {
        white-space: nowrap;
        font-size: 0.85rem;
        padding: 0.4rem 0.5rem;
    }
    .data-table {
        table-layout: auto;
    }
    .actions-cell {
        white-space: nowrap;
    }
}

.table-wrap {
    /* legacy container style: allow horizontal scroll when needed */
    overflow-x: auto;
    margin-top: 0.5rem;
}

.result-count {
    font-weight: normal;
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

.actions-cell {
    white-space: nowrap;
}

/* Align action buttons inside the actions cell */
.actions-cell { display:flex; align-items:center; justify-content:flex-end; gap:0.5rem; }
.actions-cell .btn { margin: 0; }

/* Standardize button sizing across the app for consistent look */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 40px;
    padding: 0.45rem 0.9rem;
    border-radius: 6px;
}
.btn .btn-icon { width:18px; height:18px; display:inline-flex; align-items:center; justify-content:center; }
.btn .btn-icon svg { width:18px; height:18px; }
.btn-small { padding: 0.35rem 0.6rem; font-size:0.95rem; min-height:36px; }

/* Ensure search form buttons keep their taller sizing */
.search-form .form-actions .btn { min-height:44px; }

/* --- Search form (list.php) --- */
.search-form.card {
    padding: 1.25rem 1.5rem;
}

.search-form {
    margin-bottom: 1.25rem;
}

.search-form .form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.search-form .form-group {
    margin-bottom: 0;
}

.search-form .form-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.search-form .form-group input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    width: 100%;
    min-width: 120px;
}

.search-form .form-group input:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* Clear-button helper wrapper for search/filter inputs */
.search-input-wrap {
    position: relative;
}

.search-input-wrap input {
    /* Make space for the clear "X" button */
    padding-right: 2.5rem;
}

.search-input-wrap .input-clear {
    position: absolute;
    top: 50%;
    right: 0.5rem;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    padding: 0;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-text-muted);
}

.search-input-wrap .input-clear:hover {
    color: var(--color-text);
}

/* For inputs that use a native datalist dropdown arrow, put clear button on the left */
.search-input-wrap.has-dropdown input {
    padding-left: 2.5rem;
    padding-right: 0.75rem;
}

.search-input-wrap.has-dropdown .input-clear {
    right: auto;
    left: 0.5rem;
}

.search-form .form-group-actions {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.search-form .form-group-actions .btn {
    width: auto;
}

.results-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.results-head h2 { margin: 0; }
.sort-link {
    color: var(--color-text);
    text-decoration: none;
    font-weight: 600;
}
.sort-link:hover { color: var(--color-primary); }
.results-section.card h2 {
    margin: 0 0 0.75rem 0;
}

.results-section h2 {
    font-size: 1.1rem;
    margin: 0 0 0.5rem 0;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.pagination .btn-small {
    width: auto;
}

.pagination .btn-small.current,
.pagination .btn-small.current:hover {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.pagination-info {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.no-results {
    color: var(--color-text);
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid rgba(37, 99, 235, 0.18);
    font-weight: 500;
}

.btn-small {
    padding: 0.25rem 0.6rem;
    font-size: 0.9rem;
}

.documents-table td:last-child {
    white-space: nowrap;
}

/* --- View document (view.php) --- */
.view-document-wrap {
    max-width: 1000px;
}

.document-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1.25rem;
}

.document-actions .btn {
    width: auto;
}

.delete-form {
    display: inline;
    margin: 0;
}

.delete-form .btn {
    margin-left: 0;
}

.document-meta.card {
    margin-bottom: 1rem;
}

.document-meta {
    margin-bottom: 1rem;
}

.document-meta h1 {
    margin: 0 0 0.5rem 0;
    font-size: 1.25rem;
}

.document-meta dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 1.5rem;
    margin: 0;
    font-size: 0.95rem;
}

.document-meta dt {
    margin: 0;
    font-weight: 600;
    color: var(--color-text-muted);
}

.document-meta dd {
    margin: 0;
}

.document-preview.card {
    margin-top: 0;
    padding: 0;
    overflow: hidden;
}

.document-preview {
    margin-top: 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    background: #fafbfc;
}

.document-image {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Thumbnails in list view */
.thumb-img { width: 96px; max-width: 100%; height: auto; display: block; border-radius: 6px; border: 1px solid var(--color-border); object-fit: contain; }
.thumb-placeholder { display:inline-flex; width:96px; max-width:100%; height:56px; background:#fff; border:1px solid var(--color-border); border-radius:6px; color:var(--color-text-muted); font-size:12px; align-items:center; justify-content:center; }

.document-iframe {
    width: 100%;
    min-height: 70vh;
    border: none;
}

.document-open {
    margin: 0.5rem 1rem;
    font-size: 0.9rem;
}

.document-open a {
    color: var(--color-primary);
    text-decoration: none;
}

.document-open a:hover {
    text-decoration: underline;
}

/* Results loading spinner */
.results-section { position: relative; }
.results-section.loading { opacity: 0.7; }
.results-section.loading::after {
    content: '';
    position: absolute;
    right: 1rem;
    top: 1.1rem;
    width: 18px;
    height: 18px;
    border: 3px solid rgba(0,0,0,0.08);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: masso-spin 0.9s linear infinite;
}
@keyframes masso-spin { to { transform: rotate(360deg); } }

/* --- Profile --- */
.profile-form .form-group {
    margin-bottom: 1rem;
}

.profile-form .form-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.profile-form .form-group input {
    width: 100%;
    padding: 0.75rem 0.9rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.98rem;
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: inset 0 1px 2px rgba(15,23,42,0.04);
}

.profile-form .form-group input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.profile-form .btn-primary {
    width: auto;
}

.settings-page-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.settings-page-header h1 {
    margin: 0;
    font-size: 1.75rem;
    letter-spacing: -0.02em;
}
.settings-description {
    margin: 0.35rem 0 0;
    max-width: 44rem;
    color: var(--color-text-muted);
    line-height: 1.6;
}
.settings-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.settings-pills .btn {
    padding: 0.7rem 1rem;
    border-radius: 999px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text);
}
.settings-pills .btn:hover {
    background: var(--color-background);
}
.settings-section {
    padding-top: 0.5rem;
}
.settings-section h2 {
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
}
.settings-section p {
    margin-top: 0;
    margin-bottom: 1rem;
    color: var(--color-text-muted);
}
.settings-subsection {
    background: rgba(15,23,42,0.03);
    border: 1px solid rgba(15,23,42,0.06);
    border-radius: var(--radius-sm);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}
.settings-form .form-group {
    margin-bottom: 1rem;
    width: 100%;
    max-width: 100%;
}
.settings-form .form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    align-items: start;
}
.settings-form .form-row .form-group {
    width: 100%;
}
.settings-form .form-group label,
.settings-form .form-group select,
.settings-form .form-group input {
    display: block;
    width: 100%;
}
.settings-form .form-group input,
.settings-form .form-group select {
    padding: 0.75rem 0.9rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.98rem;
    box-shadow: inset 0 1px 2px rgba(15,23,42,0.04);
}
.settings-form .form-group input:focus,
.settings-form .form-group select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(15, 61, 145, 0.12);
}
.settings-form .btn {
    min-width: 140px;
}
.data-table th,
.data-table td {
    padding: 0.65rem 0.85rem;
}
.data-table th {
    background: #f8fafc;
    color: var(--color-text);
}
.table-responsive {
    margin-top: 1rem;
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }
    .sidebar.is-open {
        transform: translateX(0);
        box-shadow: var(--shadow-hover);
    }
    .sidebar-toggle {
        display: flex;
        position: fixed;
        top: 0.8rem;
        left: 0.8rem;
        z-index: 1300;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: rgba(255,255,255,0.94);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-sm);
        color: var(--color-text);
        box-shadow: 0 2px 8px rgba(0,0,0,0.12);
        gap: 5px;
    }
    /* Show the floating hamburger button in mobile view */
    .top-bar .sidebar-toggle { display: flex; }
    .bottom-bar .sidebar-toggle {
        display: none;
    }
    .app-main { margin-left: 0; }
    .app-footer { margin-left: 0; }

    .search-form.card {
        padding: 0.75rem 0.8rem;
    }
    .search-form .form-row {
        flex-direction: column;
        gap: 0.5rem;
    }
    .search-form .form-group {
        min-width: 100%;
    }
    .search-form .form-group.form-group--sm,
    .search-form .form-group.form-group--lg {
        flex: 1 1 100%;
        max-width: 100%;
    }
    /* keep advanced fields hidden by default, user can open with button */
    .search-form .search-advanced {
        display: none;
        max-height: 0;
        opacity: 0;
        transform: translateY(-8px);
        overflow: hidden;
        transition: max-height 0.32s ease, opacity 0.22s ease, transform 0.25s ease;
        order: 2;
        padding: 0;
    }
    .search-form.advanced-open .search-advanced {
        display: block !important;
        max-height: 999px;
        opacity: 1;
        transform: none;
        padding: 1rem;
    }
    .search-form .form-actions {
        order: 3;
        width: 100%;
        justify-content: flex-end;
        margin-top: 0.5rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .search-form .form-actions .btn {
        width: auto;
    }

    .table-wrap { overflow-x: auto; }
    .data-table th, .data-table td { font-size: 0.82rem; padding: 0.35rem 0.45rem; }
    .data-table { min-width: 640px; }
}


@media (max-width: 768px) {
    .stats-row { flex-direction: column; }
    .stat-card { min-width: 100%; }
    .search-form .form-row { flex-direction: column; }
    .search-form .form-group { min-width: 100%; }
    .document-actions { flex-direction: column; align-items: flex-start; }
    .data-table { font-size: 0.9rem; }
    .data-table th, .data-table td { padding: 0.4rem 0.5rem; }
    .page-content { padding: 1rem; }
}

/* Keep action buttons aligned and visible; allow table cells to wrap so horizontal scrolling isn't necessary */
.actions-cell { white-space: nowrap; display:flex; align-items:center; justify-content:flex-end; gap:0.4rem; padding-right:0.4rem; }
.actions-cell .btn { flex: 0 0 auto; padding: 0.28rem 0.6rem; font-size:0.94rem; }

/* Keep compact columns from wrapping so values and the action buttons align nicely */
.data-table th:nth-child(6), .data-table td:nth-child(6),
.data-table th:nth-child(7), .data-table td:nth-child(7),
.data-table th:nth-child(8), .data-table td:nth-child(8),
.data-table th:nth-child(9), .data-table td:nth-child(9) {
    white-space: nowrap;
}

.masso-toast { display:block; min-width: 180px; max-width: 420px; margin: 0.5rem; padding: 0.65rem 0.9rem; border-radius: 8px; color:#fff; background: rgba(0,0,0,0.75); opacity:0; transform: translateY(6px); transition: opacity 0.18s ease, transform 0.18s ease; box-shadow: 0 6px 18px rgba(2,6,23,0.18); }
.masso-toast.show { opacity:1; transform: translateY(0); }
.masso-toast-success { background: linear-gradient(135deg, rgba(34, 197, 94, 0.95) 0%, rgba(22, 163, 74, 0.95) 100%); }
.masso-toast-error { background: linear-gradient(135deg, rgba(239, 68, 68, 0.95) 0%, rgba(219, 39, 39, 0.95) 100%); }
.masso-toast-warning { background: linear-gradient(135deg, rgba(245, 158, 11, 0.95) 0%, rgba(217, 119, 6, 0.95) 100%); }
.masso-toast-info { background: linear-gradient(135deg, rgba(15, 126, 88, 0.95) 0%, rgba(12, 106, 75, 0.95) 100%); }

/* Toasts: place in top-right by default */
#masso-toasts { position: fixed; right: 1rem; top: 1rem; bottom: auto; z-index: 1100; display:flex; flex-direction:column; align-items:flex-end; }
.masso-toast { display:flex; align-items:center; gap:0.75rem; min-width: 240px; max-width: 480px; margin: 0.6rem; padding: 0.85rem 1rem; border-radius: 10px; color:#fff; background: rgba(0,0,0,0.85); opacity:0; transform: translateY(8px); transition: opacity 0.2s ease, transform 0.2s ease; box-shadow: 0 8px 24px rgba(2,6,23,0.25); border: 1px solid rgba(255,255,255,0.1); position: relative; backdrop-filter: blur(4px); }
.masso-toast.show { opacity:1; transform: translateY(0); }
@media (max-width: 900px) {
    #masso-toasts { left: auto; right: 0.6rem; top: 0.6rem; align-items: flex-end; }
    .masso-toast { max-width: calc(100% - 1.2rem); min-width: auto; }
}
.masso-toast-success { background: linear-gradient(135deg, rgba(34, 197, 94, 0.95) 0%, rgba(22, 163, 74, 0.95) 100%); }
.masso-toast-error { background: linear-gradient(135deg, rgba(239, 68, 68, 0.95) 0%, rgba(219, 39, 39, 0.95) 100%); }
.masso-toast-warning { background: linear-gradient(135deg, rgba(245, 158, 11, 0.95) 0%, rgba(217, 119, 6, 0.95) 100%); }
.masso-toast-info { background: linear-gradient(135deg, rgba(15, 126, 88, 0.95) 0%, rgba(12, 106, 75, 0.95) 100%); }

.masso-toast-icon { font-size: 1.2rem; width: 1.4rem; height: 1.4rem; min-width: 1.4rem; text-align: center; display:flex; align-items:center; justify-content:center; font-family: 'Material Icons'; flex-shrink: 0; }
.masso-toast-message { flex: 1 1 auto; line-height:1.4; font-size: 0.95rem; word-wrap: break-word; }
.masso-toast-close { background: transparent; border: 0; color: rgba(255,255,255,0.85); font-size: 1.3rem; cursor: pointer; margin-left: 0.5rem; padding: 0; width: 1.6rem; height: 1.6rem; display:flex; align-items:center; justify-content:center; border-radius: 4px; transition: background-color 0.15s ease, color 0.15s ease; flex-shrink: 0; }
.masso-toast-close:hover { background-color: rgba(255,255,255,0.2); color: #fff; }

.masso-toast-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255,255,255,0.15); border-bottom-left-radius: 8px; border-bottom-right-radius: 8px; overflow: hidden; }
.masso-toast-progress-line { width: 100%; height: 100%; background: rgba(255,255,255,0.95); transform-origin: left; animation-name: masso-toast-progress; animation-timing-function: linear; animation-fill-mode: forwards; }

@keyframes masso-toast-progress { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.masso-confirm { position: fixed; inset: 0; display: none; /* place at top-center */ flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 1.25rem; z-index: 1200; }
.masso-confirm .masso-confirm-backdrop { position:absolute; inset:0; background: rgba(2,6,23,0.45); }
.masso-confirm .masso-confirm-panel {
    /* position fixed so the panel is centered relative to the viewport (not content flow) */
    position: fixed;
    left: 50%;
    top: 2px;
    transform: translateX(-50%);
    background: var(--color-surface);
    border-radius: 10px;
    padding: 1.25rem 1.25rem 1rem;
    width: 440px;
    max-width: calc(100% - 32px);
    box-shadow: 0 10px 30px rgba(2,6,23,0.2);
    border: 1px solid var(--color-border);
    z-index: 1201;
}
.masso-confirm-title { margin: 0 0 0.35rem 0; font-size: 1.1rem; }
.masso-confirm-text { margin: 0 0 1rem 0; color: var(--color-text-muted); font-size: 0.95rem; }

/* Modal form spacing and sizing */
.masso-confirm .form-group { margin-bottom: 1rem; }
.masso-confirm .form-group label { display: block; margin-bottom: 0.35rem; font-weight: 600; font-size: 0.95rem; }
.masso-confirm input,
.masso-confirm select,
.masso-confirm textarea {
    width: 100%;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    line-height: 1.3;
    background: var(--color-surface);
    box-shadow: inset 0 1px 2px rgba(15,23,42,0.06);
}
.masso-confirm input:focus,
.masso-confirm select:focus,
.masso-confirm textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(11,61,145,0.16);
}

.masso-confirm-actions { display:flex; gap:0.5rem; justify-content:flex-end; }
.masso-confirm .btn { min-width: 84px; }

/* When a modal is open, prevent the page behind it from scrolling */
body.modal-open { overflow: hidden; }

/* Make action buttons icon-only visually, reveal label on hover as tooltip */
.actions-cell .btn { position: relative; min-width: 40px; padding: 0.35rem; display:inline-flex; align-items:center; justify-content:center; }
.actions-cell .btn .btn-text { display: none; }
.actions-cell .btn::after {
    content: attr(data-label);
    position: absolute;
    right: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.8);
    color: #fff;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 0.85rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease, transform 0.12s ease;
}
.actions-cell .btn:hover::after { opacity: 1; transform: translateY(-50%) translateX(-4px); }

/* Page-card for separate paged results (created when using keyset Next) */
.page-card {
    margin: 1rem 0 0.75rem 0;
    padding: 0.75rem;
}
.page-card .table-wrap { overflow-x: auto; }
.page-card .data-table { margin: 0; }

/* Image Gallery for multiple document images */
.image-gallery {
    position: relative;
    width: 100%;
    background: #fafbfc;
}

.gallery-container {
    position: relative;
    width: 100%;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
}

.gallery-item {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
}

.gallery-item.active {
    display: flex;
    position: relative;
}

.gallery-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

.gallery-counter {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
}

.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 4px;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, opacity 0.2s ease;
    opacity: 0.7;
    z-index: 10;
    padding: 0;
}

.gallery-container:hover .gallery-nav {
    opacity: 1;
}

.gallery-nav:hover {
    background: rgba(0, 0, 0, 0.8);
}

.gallery-prev {
    left: 12px;
}

.gallery-next {
    right: 12px;
}

.gallery-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.05);
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    padding: 0;
}

.dot:hover {
    background: rgba(0, 0, 0, 0.6);
}

.dot.active {
    background: var(--color-primary);
    transform: scale(1.2);
}

@media (max-width: 768px) {
    .gallery-container {
        max-height: 400px;
    }
    .gallery-nav {
        width: 52px;
        height: 52px;
        font-size: 1.8rem;
        opacity: 1 !important;
        background: rgba(0, 0, 0, 0.65) !important;
    }
    .gallery-nav:active {
        background: rgba(0, 0, 0, 0.9) !important;
    }
    .gallery-prev {
        left: 10px;
    }
    .gallery-next {
        right: 10px;
    }
}

.form-help {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin: 0.5rem 0 0 0;
    display: block;
}

.btn-group {
    display: inline-flex;
    gap: 0.5rem;
}
.page-controls {
    display:flex;
    gap:0.5rem;
    justify-content:center;
    align-items:center;
    margin-top:0.65rem;
}
.page-card.hidden { display: none; }

/* Help Icon Button */
.btn-help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-primary-light);
    color: var(--color-primary);
    border: none;
    cursor: pointer;
    margin-left: 0.75rem;
    transition: all 0.2s ease;
    vertical-align: middle;
}

.btn-help:hover {
    background: var(--color-primary);
    color: #fff;
    transform: scale(1.1);
}

.btn-help .material-icons {
    font-size: 18px;
}

/* Tutorial Modal */
.tutorial-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tutorial-modal.active {
    display: flex;
    opacity: 1;
}

.tutorial-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
}

.tutorial-content {
    position: relative;
    background: var(--color-surface);
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - 40px);
    border-radius: 16px;
    padding: 1.75rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow-y: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.tutorial-content::-webkit-scrollbar {
    display: none;
}

.tutorial-modal.active .tutorial-content {
    transform: translateY(0);
}

.tutorial-close {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tutorial-close:hover {
    background: var(--color-error-bg);
    color: var(--color-error);
}

.tutorial-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.tutorial-icon-wrap {
    width: 52px;
    height: 52px;
    background: var(--color-primary-light);
    color: var(--color-primary);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
}

.tutorial-icon-wrap .material-icons {
    font-size: 28px;
}

.tutorial-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
    letter-spacing: -0.02em;
}

.tutorial-body {
    color: var(--color-text-muted);
    line-height: 1.7;
}

.tutorial-step {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.02);
    border-radius: 12px;
    transition: background 0.2s ease;
}

.tutorial-step:hover {
    background: rgba(15, 23, 42, 0.04);
}

.step-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    background: #fff;
    color: var(--color-primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.step-icon .material-icons {
    font-size: 20px;
}

.step-text h3 {
    margin: 0 0 0.25rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
}

.step-text p {
    margin: 0;
    font-size: 0.92rem;
}

.tutorial-footer {
    margin-top: 2rem;
}

.tutorial-footer .btn {
    width: 100%;
    padding: 0.8rem;
    font-weight: 600;
}

