:root {
    --bg: #f8fafc;
    --bg-soft: #f1f5f9;
    --bg-elevated: #ffffff;

    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-soft: #94a3b8;

    --primary: #2563eb;
    --primary-strong: #1d4ed8;
    --primary-soft: #eff6ff;

    --success: #16a34a;
    --success-soft: #f0fdf4;

    --warning: #ea580c;
    --warning-soft: #fff7ed;

    --danger: #dc2626;
    --danger-soft: #fef2f2;

    --card-border: rgba(15, 23, 42, 0.08);
    --card-border-strong: rgba(15, 23, 42, 0.12);

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 20px 60px rgba(15, 23, 42, 0.10);

    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --radius-xl: 22px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text-main);
    line-height: 1.5;
}

body::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

body::-webkit-scrollbar-track {
    background: #e2e8f0;
}

body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
    border: 2px solid #e2e8f0;
}

body::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

body {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #e2e8f0;
}

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

a:hover {
    color: var(--primary);
}

img {
    max-width: 100%;
}

/* Layout base */
.app-content {
 width: 100%;
}

.app-footer {
    text-align: center;
    padding: 18px 0 28px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Cards */
.card {
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    padding: 18px;
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow-sm);
}

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

.kpi {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 110px;
    justify-content: center;
}

.kpi .stat-label,
.stat-label {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .02em;
}

.kpi .stat-value,
.stat-value {
    font-size: 28px;
    line-height: 1.05;
    font-weight: 800;
    color: var(--text-main);
}

/* Grid */
.grid {
    display: grid;
    gap: 16px;
}

.grid-4 {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.grid-5 {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

/* Text helpers */
.muted {
    color: var(--text-muted);
    font-size: 14px;
}

.detail-title {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-main);
}

.detail-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: #fff;
    color: var(--text-main);
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: .18s ease;
    box-shadow: var(--shadow-sm);
}

.btn:hover {
    background: #f8fafc;
    border-color: var(--card-border-strong);
    color: var(--text-main);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: transparent;
}

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

.btn-ghost {
    background: transparent;
    box-shadow: none;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--card-border);
    color: var(--text-main);
    font-size: 15px;
    cursor: pointer;
    transition: .18s ease;
}

.icon-btn:hover {
    border-color: var(--card-border-strong);
    background: #f8fafc;
    color: var(--primary);
}

.icon-btn i {
    pointer-events: none;
}

.icon-btn.primary {
    background: var(--primary-soft);
    color: var(--primary);
    border-color: rgba(37, 99, 235, 0.14);
}

.icon-btn.danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: rgba(220, 38, 38, 0.12);
}

/* Forms */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
}

.input {
    min-width: 140px;
}

.input-small {
    max-width: 90px;
}

input[type="text"],
input[type="email"],
input[type="search"],
input[type="password"],
input[type="datetime-local"],
input[type="number"],
input[type="file"],
select,
textarea {
    width: 100%;
    background: #fff;
    border: 1px solid var(--card-border);
    color: var(--text-main);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
    transition: .18s ease;
}

input::placeholder,
textarea::placeholder {
    color: var(--text-soft);
}

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(37, 99, 235, 0.35);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}

textarea {
    resize: vertical;
    min-height: 120px;
}

.form-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.form-grid label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
}

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.field-check {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: #f8fafc;
    color: var(--text-main);
    font-weight: 700;
}

.field-check input {
    width: auto;
}

/* Alerts */
.alert {
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 14px;
    border: 1px solid var(--card-border);
    font-size: 14px;
}

.alert-danger {
    background: var(--danger-soft);
    border-color: rgba(220, 38, 38, 0.12);
    color: #991b1b;
}

.alert-success {
    background: var(--success-soft);
    border-color: rgba(22, 163, 74, 0.12);
    color: #166534;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-warning {
    background: #ffedd5;
    color: #9a3412;
}

.badge-info {
    background: #dbeafe;
    color: #1d4ed8;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

.table-responsive::-webkit-scrollbar {
    height: 8px;
}

.table-responsive::-webkit-scrollbar-track {
    background: #e2e8f0;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: transparent;
}

.table th,
.table td {
    padding: 12px 10px;
    text-align: left;
    vertical-align: middle;
}

.table th {
    color: var(--text-muted);
    font-weight: 700;
    font-size: 13px;
    border-bottom: 1px solid var(--card-border);
}

.table tr {
    border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

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

.table-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* Pagination */
.pagination {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 12px;
    flex-wrap: wrap;
}

.pagination a {
    padding: 7px 10px;
    border-radius: 10px;
    border: 1px solid var(--card-border);
    background: #fff;
    color: var(--text-main);
    font-size: 14px;
    font-weight: 700;
}

.pagination a:hover {
    background: #f8fafc;
}

.pagination a.active {
    background: var(--primary);
    color: #fff;
    border-color: transparent;
}

/* Old master-detail compatibility */
.master-detail {
    display: flex;
    gap: 16px;
    min-height: 460px;
}

.panel-left {
    width: 32%;
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    padding: 12px;
    display: flex;
    flex-direction: column;
}

.panel-right {
    flex: 1;
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 14px;
    padding: 12px;
    min-height: 100%;
}

.panel-title {
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-main);
}

.client-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    max-height: 520px;
}

.client-list::-webkit-scrollbar {
    width: 8px;
}

.client-list::-webkit-scrollbar-track {
    background: #e2e8f0;
    border-radius: 10px;
}

.client-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.client-list {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #e2e8f0;
}

.client-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--card-border);
    color: var(--text-main);
    transition: .15s ease;
    cursor: pointer;
}

.client-item:hover {
    border-color: rgba(37, 99, 235, 0.25);
    background: #f8fafc;
}

.client-item.active {
    background: #eff6ff;
    border-color: rgba(37, 99, 235, 0.25);
}

.client-name {
    font-weight: 700;
}

.client-meta {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    text-align: right;
}

.client-meta .icon-btn {
    width: 32px;
    height: 32px;
}

.client-phone {
    color: var(--text-muted);
    font-size: 14px;
    letter-spacing: 0.2px;
}

/* Upload zone */
.upload-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.upload-dropzone {
    border: 1.5px dashed #cbd5e1;
    background: #fff;
    padding: 32px 20px;
    border-radius: 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.upload-dropzone:hover {
    border-color: var(--primary);
    background: #f8fbff;
    transform: translateY(-1px);
}

.upload-dropzone.is-dragover {
    border-color: var(--primary);
    background: #eff6ff;
}

.upload-icon {
    font-size: 32px;
    margin-bottom: 8px;
    color: var(--primary);
}

.upload-title {
    font-weight: 800;
    margin-bottom: 4px;
    font-size: 18px;
    color: var(--text-main);
}

.upload-note {
    color: var(--text-muted);
    font-size: 14px;
}

.upload-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
}

/* Modal reusable */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 1000;
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.modal-shell {
    width: min(1100px, 100%);
    background: #fff;
    border-radius: 18px;
    border: 1px solid var(--card-border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: #fff;
    border-bottom: 1px solid var(--card-border);
}

.modal-title {
    font-weight: 800;
    margin: 0;
    color: var(--text-main);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 20px;
    cursor: pointer;
}

.modal-body {
    padding: 0;
    height: min(80vh, 720px);
    background: #fff;
}

.modal-body iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    background: #fff;
}

/* Legacy header compatibility */
.app-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: #fff;
    border-bottom: 1px solid var(--card-border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.logo img {
    height: 36px;
    width: auto;
    display: block;
}

.menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 22px;
    padding: 8px;
    border-radius: 8px;
}

.menu-toggle:hover {
    color: var(--primary);
    cursor: pointer;
}

.nav-links {
    display: flex;
    gap: 10px;
}

.nav-links a {
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--text-muted);
}

.nav-links a:hover,
.nav-links a.active {
    background: #f8fafc;
    color: var(--text-main);
}

.spacer {
    flex: 1;
}

.user-chip {
    padding: 6px 12px;
    border-radius: 999px;
    background: #f8fafc;
    color: var(--text-muted);
    border: 1px solid var(--card-border);
}

.user-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-logout {
    display: none;
}

.nav-logout-btn {
    background: none;
    border: none;
    color: var(--danger);
    font-weight: 700;
    display: flex;
    gap: 8px;
    align-items: center;
    cursor: pointer;
}

.nav-admin {
    color: #6d8d12;
    font-weight: 700;
}

.nav-admin.highlight {
    background: #a9cb2d;
    color: #02213d !important;
    padding: 6px 10px;
    border-radius: 8px;
}

/* Mobile */
@media (max-width: 1080px) {
    .master-detail {
        flex-direction: column;
    }

    .panel-left,
    .panel-right {
        width: 100%;
    }
}

@media (max-width: 900px) {
    .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .nav-links {
        display: none;
        position: fixed;
        top: 64px;
        right: 12px;
        width: min(320px, calc(100% - 24px));
        background: #fff;
        border: 1px solid var(--card-border);
        border-radius: 14px;
        padding: 10px;
        flex-direction: column;
        gap: 6px;
        box-shadow: var(--shadow-lg);
        z-index: 50;
    }

    .nav-links a {
        padding: 10px 12px;
        border-radius: 10px;
    }

    body.mobile-nav-open .nav-links {
        display: flex;
    }

    body.mobile-nav-open .nav-logout {
        display: block;
        margin-top: 12px;
    }
}

@media (max-width: 760px) {
    .app-content {
        padding: 18px 14px 32px;
    }

    .table th:nth-child(3),
    .table td:nth-child(3),
    .table th:nth-child(4),
    .table td:nth-child(4) {
        display: none;
    }
}

@media (max-width: 640px) {
    .card {
        padding: 14px;
        border-radius: 16px;
    }

    .btn,
    .icon-btn {
        min-height: 40px;
    }

    .filters {
        flex-direction: column;
        align-items: stretch;
    }

    .form-actions,
    .upload-actions,
    .detail-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .modal-overlay {
        padding: 12px;
    }

    .modal-shell {
        border-radius: 16px;
    }
}
