:root {
    --primary: #2f80ab;
    --secondary: #95c11f;
    --bg: #f5f9fc;
    --text: #1f2a36;
    --muted: #67768a;
    --border: #d9e3ec;
    --surface: #ffffff;
    --danger: #d64545;
    --success: #23875f;
    --shadow: 0 18px 50px rgba(26, 54, 93, 0.08);
    --radius: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: Inter, Arial, sans-serif; color: var(--text); background: var(--bg); }
body { min-height: 100vh; }

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

h1, h2, h3 { margin: 0 0 .4rem; }
p { line-height: 1.5; }
small, .muted { color: var(--muted); }

.app-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.main-content { padding: 28px; }
.main-content--auth { display: grid; place-items: center; min-height: 100vh; }

.sidebar {
    background: linear-gradient(180deg, #1d5f82, #2f80ab);
    color: white;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}
.brand-card {
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 22px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.brand-logo {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: var(--secondary);
    color: white;
    font-weight: 800;
    display: grid;
    place-items: center;
    font-size: 1.4rem;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.brand-logo--lg { width: 72px; height: 72px; font-size: 2rem; }
.brand-title { font-size: 1.1rem; font-weight: 700; }
.brand-subtitle { opacity: .8; font-size: .92rem; }

.nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.nav a {
    color: white;
    opacity: .9;
    padding: 12px 14px;
    border-radius: 14px;
    transition: .2s ease;
    font-weight: 600;
}
.nav a.active, .nav a:hover {
    background: rgba(255,255,255,.14);
    text-decoration: none;
    opacity: 1;
}

.sidebar-footer { margin-top: auto; display: grid; gap: 12px; }
.license-box {
    background: rgba(255,255,255,.1);
    border-radius: 16px;
    padding: 14px;
    display: grid;
    gap: 4px;
}
.license-box small { color: rgba(255,255,255,.8); }
.license-box span { opacity: .82; font-size: .9rem; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 24px;
}
.topbar-badges { display: flex; gap: 10px; flex-wrap: wrap; }

.card, .auth-card, .stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid rgba(47,128,171,.08);
}
.card { padding: 22px; }
.card-subtle {
    background: linear-gradient(180deg, rgba(47,128,171,.035), rgba(149,193,31,.03));
}
.auth-card {
    width: min(560px, calc(100vw - 32px));
    padding: 32px;
}
.auth-brand {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 24px;
}
.stat-card {
    padding: 18px;
    display: grid;
    gap: 8px;
}
.stat-card span { color: var(--muted); }
.stat-card strong { font-size: 2rem; }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
}

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: 420px 1fr 1fr; }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.col-span-1 { grid-column: span 1; }
.col-span-2 { grid-column: span 2; }

.stack { display: grid; gap: 14px; }
.stack-lg { display: grid; gap: 22px; }
.form-group { display: grid; gap: 8px; }
label { font-size: .95rem; font-weight: 600; }
input, select, textarea, button {
    font: inherit;
}
input, select, textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    color: var(--text);
}
textarea { min-height: 110px; resize: vertical; }

.btn {
    border: 0;
    border-radius: 14px;
    padding: 12px 16px;
    cursor: pointer;
    transition: .2s ease;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none !important;
}
.btn-sm { padding: 8px 10px; border-radius: 12px; font-size: .9rem; }
.btn-full { width: 100%; }
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: #edf4f8; color: var(--text); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: #fce8e8; color: var(--danger); }
.btn:hover { transform: translateY(-1px); filter: saturate(1.03); }

.form-actions, .actions-inline {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left;
    color: var(--muted);
    font-size: .86rem;
    padding: 12px;
    border-bottom: 1px solid var(--border);
}
tbody td {
    padding: 14px 12px;
    border-bottom: 1px solid #edf2f7;
    vertical-align: top;
}
tbody tr:hover { background: rgba(47,128,171,.02); }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    background: #edf4f8;
    color: var(--text);
    font-weight: 700;
    font-size: .82rem;
}
.badge-success { background: rgba(35, 135, 95, .12); color: var(--success); }
.badge-danger { background: rgba(214,69,69,.12); color: var(--danger); }

.alert {
    padding: 14px 18px;
    border-radius: 14px;
    margin-bottom: 18px;
}
.alert-success { background: rgba(35,135,95,.12); color: var(--success); }
.alert-danger { background: rgba(214,69,69,.12); color: var(--danger); }

.preview-box {
    padding: 14px;
    border: 1px dashed var(--border);
    border-radius: 16px;
    background: white;
    min-height: 68px;
}
.cost-summary {
    display: grid;
    gap: 10px;
}
.cost-summary div {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.cost-summary strong { font-size: 1.6rem; }

.signature-canvas {
    width: 100%;
    height: 180px;
    border: 1px dashed var(--border);
    border-radius: 16px;
    background: white;
    touch-action: none;
}

.rental-item-head,
.rental-item-row {
    display: grid;
    grid-template-columns: 2.2fr .9fr .9fr .95fr 1.2fr 1.2fr auto;
    gap: 10px;
    align-items: start;
}
.rental-item-head {
    color: var(--muted);
    font-size: .86rem;
    padding: 0 0 8px;
}
.rental-item-row {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 16px;
    margin-bottom: 12px;
    background: white;
}
.rental-item-row input,
.rental-item-row select { min-width: 0; }

.kv-list {
    display: grid;
    gap: 10px;
}
.kv-list > div {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eef3f7;
}
.kv-list dt { color: var(--muted); font-weight: 600; }
.kv-list dd { margin: 0; text-align: right; }

.divider {
    height: 1px;
    background: #edf2f7;
    margin: 20px 0;
}
.list-clean {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 12px;
}
.document-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: white;
}
.hidden { display: none !important; }

@media (max-width: 1200px) {
    .grid-3 { grid-template-columns: 1fr; }
    .col-span-2 { grid-column: span 1; }
}
@media (max-width: 1024px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: sticky; top: 0; z-index: 20; }
    .grid-2, .grid-4 { grid-template-columns: 1fr; }
    .rental-item-head { display: none; }
    .rental-item-row { grid-template-columns: 1fr; }
    .topbar { flex-direction: column; }
}

body.sidebar-open {
    overflow: hidden;
}

.sidebar-overlay {
    display: none;
}

.menu-toggle {
    display: none;
}

.topbar-main {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sync-toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 80;
    background: rgba(31, 42, 54, .94);
    color: #fff;
    border-radius: 14px;
    padding: 12px 16px;
    box-shadow: 0 18px 50px rgba(26, 54, 93, 0.18);
}

.signature-preview-image {
    display: block;
    width: 100%;
    max-height: 180px;
    object-fit: contain;
    border: 1px dashed var(--border);
    border-radius: 16px;
    background: #fff;
    margin-bottom: 10px;
}

.rental-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 22px;
    align-items: start;
}

.rental-main,
.rental-side {
    min-width: 0;
}

.sticky-summary,
.sticky-actions {
    position: sticky;
    top: 24px;
}

.summary-list {
    display: grid;
    gap: 10px;
    margin: 0 0 16px;
}
.summary-list > div {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eef3f7;
}
.summary-list dt {
    color: var(--muted);
    font-weight: 600;
}
.summary-list dd {
    margin: 0;
    text-align: right;
}

.item-field {
    display: grid;
    gap: 6px;
}

.field-label {
    display: none;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 700;
}

.item-field-action {
    align-self: end;
}

.form-group small {
    margin-top: -2px;
}

@media (max-width: 1320px) {
    .rental-layout {
        grid-template-columns: 1fr;
    }

    .sticky-summary,
    .sticky-actions {
        position: static;
    }
}

@media (max-width: 1024px) {
    .app-shell {
        display: block;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(16, 24, 40, 0.44);
        z-index: 39;
    }

    body.sidebar-open .sidebar-overlay {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(320px, 86vw);
        max-height: 100vh;
        overflow-y: auto;
        transform: translateX(-110%);
        transition: transform .24s ease;
        z-index: 40;
        box-shadow: 24px 0 60px rgba(0, 0, 0, 0.22);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .main-content {
        padding: 18px;
    }

    .topbar {
        position: sticky;
        top: 0;
        z-index: 15;
        background: var(--bg);
        padding-bottom: 10px;
        align-items: stretch;
    }

    .topbar-main {
        align-items: flex-start;
    }

    .grid-2,
    .grid-4,
    .rental-form-grid {
        grid-template-columns: 1fr;
    }

    .rental-item-head {
        display: none;
    }

    .rental-item-row {
        grid-template-columns: 1fr;
        gap: 14px;
        padding: 16px;
    }

    .field-label {
        display: block;
    }

    .item-field-action .btn {
        width: 100%;
    }
}

@media (max-width: 640px) {
    .card,
    .auth-card,
    .stat-card {
        border-radius: 18px;
    }

    .main-content {
        padding: 14px;
    }

    .topbar-badges {
        gap: 8px;
    }

    .badge {
        padding: 7px 10px;
    }
}
