:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --text: #172033;
    --muted: #6d7685;
    --line: #e3e7ed;
    --primary: #1f6feb;
    --primary-dark: #174ea6;
    --sidebar: #111827;
    --sidebar-text: #d1d5db;
    --sidebar-active: #ffffff;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: inherit; text-decoration: none; }
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 260px;
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 24px 18px;
    flex-shrink: 0;
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    font-weight: 700;
    margin-bottom: 32px;
}
.brand-mark {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--primary);
}
.main-nav { display: grid; gap: 6px; }
.main-nav a {
    padding: 12px 14px;
    border-radius: 10px;
    color: var(--sidebar-text);
}
.main-nav a:hover,
.main-nav a.is-active {
    background: rgba(255,255,255,.11);
    color: var(--sidebar-active);
}
.main-area { flex: 1; min-width: 0; }
.topbar {
    min-height: 84px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 28px;
}
.topbar h1 { margin: 0; font-size: 24px; }
.topbar p { margin: 3px 0 0; color: var(--muted); }
.user-pill {
    background: var(--bg);
    padding: 9px 13px;
    border-radius: 999px;
    color: var(--muted);
    white-space: nowrap;
}
.menu-toggle { display: none; }
.content { padding: 28px; }
.card, .stat-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card { padding: 24px; margin-bottom: 20px; }
.card h2 { margin: 0 0 10px; }
.card p { color: var(--muted); }
.grid { display: grid; gap: 20px; margin-bottom: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card { padding: 22px; }
.stat-card strong { display: block; font-size: 32px; }
.stat-card span { color: var(--muted); }
.page-actions { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.btn {
    border: 0;
    border-radius: 10px;
    padding: 11px 16px;
    cursor: pointer;
    font-weight: 600;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.empty-state {
    border: 1px dashed var(--line);
    border-radius: 12px;
    padding: 28px;
    text-align: center;
    color: var(--muted);
    margin-top: 20px;
}
.empty-state strong { display: block; color: var(--text); margin-bottom: 6px; }

.stat-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.stat-link:hover {
    transform: translateY(-2px);
}

.compact-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.compact-list a {
    display: block;
    padding: 12px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    background: #ffffff;
}

.compact-list a:hover {
    border-color: #2563eb;
    background: #f8fafc;
}

.compact-list strong {
    display: block;
    color: #0f172a;
}

.compact-list span {
    display: block;
    margin-top: 3px;
    color: #64748b;
    font-size: 14px;
}

.list-toolbar {
    display: flex;
    justify-content: flex-end;
    margin: 18px 0 14px;
}

.quick-search-input {
    width: min(100%, 360px);
    padding: 11px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    font-size: 14px;
    background: #ffffff;
}

.quick-search-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

@media (max-width: 900px) {
    .sidebar { position: fixed; inset: 0 auto 0 0; transform: translateX(-100%); transition: .2s; z-index: 10; }
    .sidebar.is-open { transform: translateX(0); }
    .menu-toggle { display: inline-flex; border: 0; background: var(--bg); border-radius: 8px; padding: 8px 10px; }
    .grid-2, .grid-4 { grid-template-columns: 1fr; }
    .topbar { align-items: flex-start; }
}

/* Login */
.auth-body {
    min-height: 100vh;
    background: #f4f6fb;
}
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border: 1px solid #e7eaf0;
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(20, 30, 60, .10);
    padding: 32px;
}
.login-brand {
    margin-bottom: 24px;
}
.muted {
    color: #6b7280;
}
.form-stack {
    display: grid;
    gap: 16px;
    margin-top: 24px;
}
.form-stack label {
    display: grid;
    gap: 8px;
    font-weight: 600;
}
.form-stack input {
    width: 100%;
    border: 1px solid #d8dde8;
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 15px;
}
.btn {
    border: 0;
    border-radius: 10px;
    padding: 12px 16px;
    font-weight: 700;
    cursor: pointer;
}
.btn-primary {
    background: #1f2937;
    color: #fff;
}
.alert {
    margin-top: 16px;
    border-radius: 10px;
    padding: 12px 14px;
}
.alert-error {
    background: #fee2e2;
    color: #991b1b;
}
.login-hint {
    margin-top: 18px;
    color: #6b7280;
    font-size: 13px;
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.logout-link {
    color: #6b7280;
    text-decoration: none;
    font-weight: 600;
}
.logout-link:hover {
    color: #111827;
}

/* CRUD / Data views */
.card-header,
.split-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.btn-secondary {
    background: #eef2f7;
    color: #1f2937;
}
.table-wrap { overflow-x: auto; margin-top: 18px; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.data-table th,
.data-table td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    text-align: left;
}
.data-table th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.table-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    white-space: nowrap;
}
.table-actions form { margin: 0; }
.link {
    border: 0;
    background: transparent;
    padding: 0;
    color: var(--primary);
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
}
.link.danger { color: #b91c1c; }
.muted-small { color: var(--muted); font-size: 13px; }
.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 12px;
    font-weight: 700;
}
.badge-green { background: #dcfce7; color: #166534; }
.badge-gray { background: #e5e7eb; color: #374151; }
.form-card h2 { margin-bottom: 4px; }
.form-section {
    border-top: 1px solid var(--line);
    padding-top: 20px;
    margin-top: 22px;
}
.form-section h3 { margin: 0 0 14px; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.form-card label {
    display: grid;
    gap: 8px;
    font-weight: 700;
}
.form-card input,
.form-card select,
.form-card textarea {
    width: 100%;
    border: 1px solid #d8dde8;
    border-radius: 10px;
    padding: 11px 13px;
    font: inherit;
    background: #fff;
}
.form-card textarea { resize: vertical; }
.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 10px !important;
    align-self: end;
    min-height: 42px;
}
.checkbox-label input { width: auto; }
.field-error { color: #b91c1c; font-size: 13px; font-weight: 600; }
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}
.object-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}
.object-hero h2 { margin: 10px 0 4px; font-size: 28px; }
.object-hero p { margin: 0; }
.object-number {
    text-align: right;
    color: var(--muted);
}
.object-number strong {
    display: block;
    color: var(--text);
    font-size: 22px;
}
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 20px;
}
.tabs a {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 9px 13px;
    color: var(--muted);
    font-weight: 700;
}
.tabs a.is-active { color: #fff; background: var(--primary); border-color: var(--primary); }
.detail-card dl {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 12px 16px;
    margin: 16px 0 0;
}
.detail-card dt { color: var(--muted); font-weight: 700; }
.detail-card dd { margin: 0; }


.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-top: 24px;
}

.detail-grid > div {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 16px 18px;
    min-height: 82px;
}

.detail-grid span {
    display: block;
    font-size: 13px;
    line-height: 1.3;
    color: #64748b;
    margin-bottom: 7px;
}

.detail-grid strong {
    display: block;
    font-size: 16px;
    line-height: 1.35;
    color: #0f172a;
    font-weight: 700;
    word-break: break-word;
}

.notes-block {
    margin-top: 24px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 18px;
}

.notes-block h3 {
    margin: 0 0 8px;
    font-size: 16px;
}

.notes-block p {
    margin: 0 0 16px;
    color: #334155;
    line-height: 1.6;
}

@media (max-width: 700px) {
    .form-grid,
    .detail-card dl { grid-template-columns: 1fr; }
    .object-hero,
    .card-header,
    .split-actions { align-items: flex-start; flex-direction: column; }
    .object-number { text-align: left; }
    .table-actions { flex-direction: column; align-items: flex-start; }
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}
.checkbox-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    background: #fff;
    min-height: auto;
}
@media (max-width: 900px) {
    .checkbox-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
    .checkbox-grid { grid-template-columns: 1fr; }
}
