:root {
    --bg: #f4f1eb;
    --panel: #fff;
    --panel2: #fbf8f3;
    --line: #e6ddcf;
    --text: #241c15;
    --muted: #76685a;
    --brand: #8b4b1f;
    --brand2: #c07a30;
    --navy: #17324f;
    --navy2: #2a5f92;
    --green: #188857;
    --amber: #d18a12;
    --red: #c3473d;
    --shadow: 0 18px 48px rgba(63,44,22,.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
    color: var(--text);
    background: radial-gradient(circle at top right, rgba(192,122,48,.08), transparent 22%),
                radial-gradient(circle at bottom left, rgba(23,50,79,.07), transparent 18%),
                var(--bg);
    font-size: 0.95rem;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand2); }

/* ===== LAYOUT ===== */
.app-layout {
    display: grid;
    grid-template-columns: 270px 1fr;
    min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
    background: linear-gradient(180deg, #fffaf4 0%, #f8efe3 100%);
    border-right: 1px solid var(--line);
    padding: 18px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 8px 8px 18px;
    border-bottom: 1px solid var(--line);
}

.sidebar-brand .logo {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--brand), var(--brand2));
    border-radius: 16px;
    color: #fff;
    font-size: 1.4rem;
    font-weight: 900;
    box-shadow: var(--shadow);
}

.sidebar-brand h1 {
    margin: 0;
    font-size: 1rem;
    color: var(--brand);
    line-height: 1.1;
}

.sidebar-brand small {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
    margin-top: 4px;
}

.nav-title {
    margin: 18px 8px 10px;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.nav-btn {
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    padding: 12px 14px;
    border-radius: 14px;
    text-align: left;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 6px;
    transition: 0.18s ease;
    font-size: 0.92rem;
}

.nav-btn:hover, .nav-btn.active {
    background: #fff;
    border-color: var(--line);
    box-shadow: var(--shadow);
    color: var(--brand);
}

.nav-btn .icon { font-size: 1.1rem; }

.sidebar-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.sidebar-section .nav-title { margin-top: 0; }

/* ===== MAIN ===== */
.main-content {
    padding: 20px;
    min-width: 0;
}

/* ===== TOPBAR ===== */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.topbar-left h2 {
    margin: 0;
    font-size: 1.3rem;
    color: var(--brand);
}

.topbar-left p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,.78);
    backdrop-filter: blur(10px);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 8px 14px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--brand), var(--brand2));
    color: #fff;
    font-weight: 900;
    font-size: 0.85rem;
}

/* ===== CARDS ===== */
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 18px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.card-header h3 {
    margin: 0;
    color: var(--brand);
    font-size: 1.1rem;
}

/* ===== KPI CARDS ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

.kpi-card {
    background: linear-gradient(180deg, #fff 0%, #fcf8f2 100%);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.kpi-card .label {
    font-size: 0.82rem;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: 6px;
}

.kpi-card .value {
    font-size: 1.7rem;
    font-weight: 900;
    color: var(--brand);
}

.kpi-card .tag {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 900;
    margin-top: 6px;
}

.kpi-card .tag.up { background: #ebf8ef; color: var(--green); }
.kpi-card .tag.down { background: #fdeae8; color: var(--red); }
.kpi-card .tag.neutral { background: #f7eddc; color: var(--brand); }

/* ===== TABLES ===== */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    font-size: 0.92rem;
}

th {
    background: #fbf4ea;
    color: var(--brand);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 800;
}

tr:hover td { background: rgba(247,237,220,.3); }

/* ===== STATUS BADGES ===== */
.status {
    display: inline-flex;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 900;
}

.status.ok { background: #ebf8ef; color: var(--green); }
.status.warn { background: #fff4df; color: var(--amber); }
.status.bad { background: #fdeae8; color: var(--red); }
.status.neutral { background: #f2ece4; color: var(--muted); }
.status.type-mp { background: #eef4fb; color: var(--navy2); }
.status.type-h { background: #fff4df; color: var(--amber); }
.status.type-c { background: #ebf8ef; color: var(--green); }

.badge {
    display: inline-flex;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 900;
}

.badge-mp { background: #eef4fb; color: var(--navy2); }
.badge-pp { background: #f7eddc; color: var(--brand); }
.badge-pt { background: #ebf8ef; color: var(--green); }

/* ===== BUTTONS ===== */
.btn {
    border: none;
    border-radius: 14px;
    padding: 10px 16px;
    font-weight: 800;
    cursor: pointer;
    transition: 0.18s ease;
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover { transform: translateY(-1px); }

.btn-primary {
    background: var(--brand);
    color: #fff;
}

.btn-primary:hover { background: var(--brand2); color: #fff; }

.btn-outline {
    background: #fff;
    border: 1px solid var(--line);
    color: var(--text);
}

.btn-outline:hover { border-color: var(--brand); color: var(--brand); }

.btn-outline.active {
    background: #f7eddc;
    color: var(--brand);
    border-color: #e8c8a5;
}

.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { background: #14704a; color: #fff; }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #a33b32; color: #fff; }

.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy2); color: #fff; }

.btn-sm { padding: 7px 12px; font-size: 0.82rem; border-radius: 10px; }

/* ===== TOOLBAR / FILTERS ===== */
.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    align-items: center;
}

/* ===== FORMS ===== */
.form-group { margin-bottom: 14px; }

.form-group label {
    display: block;
    font-size: 0.84rem;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 700;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    font-size: 0.92rem;
    color: var(--text);
    background: #fff;
    transition: 0.18s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(139,75,31,.1);
}

select.form-control {
    appearance: auto;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 16px;
}

/* ===== GRID LAYOUTS ===== */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.workspace { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 14px; }

/* ===== MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(36,28,21,.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal-box {
    background: #fff;
    border-radius: 24px;
    padding: 24px;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 24px 64px rgba(36,28,21,.2);
}

.modal-box h3 {
    margin: 0 0 16px;
    color: var(--brand);
}

/* ===== ALERTS ===== */
.alert {
    padding: 12px 16px;
    border-radius: 14px;
    margin-bottom: 14px;
    font-size: 0.9rem;
    font-weight: 700;
}

.alert-success { background: #ebf8ef; color: var(--green); border: 1px solid #c3e6cd; }
.alert-error { background: #fdeae8; color: var(--red); border: 1px solid #f0c5c1; }
.alert-warning { background: #fff4df; color: var(--amber); border: 1px solid #f0d89b; }

/* ===== SIIGO CARD ===== */
.siigo-status {
    background: linear-gradient(135deg, rgba(42,95,146,.08), rgba(42,95,146,.02));
    border: 1px solid #d4e2ef;
    border-radius: 18px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.siigo-status h4 { margin: 0 0 4px; color: var(--navy); }
.siigo-status .dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 4px rgba(24,136,87,.12);
    display: inline-block;
}

/* ===== LOGIN ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top right, rgba(192,122,48,.12), transparent 30%),
                radial-gradient(circle at bottom left, rgba(23,50,79,.1), transparent 25%),
                var(--bg);
}

.login-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 28px;
    padding: 36px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 24px 64px rgba(63,44,22,.12);
    text-align: center;
}

.login-card .logo {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--brand), var(--brand2));
    border-radius: 20px;
    color: #fff;
    font-size: 1.8rem;
    font-weight: 900;
    box-shadow: var(--shadow);
}

.login-card h2 {
    margin: 0 0 4px;
    color: var(--brand);
}

.login-card .subtitle {
    color: var(--muted);
    margin: 0 0 24px;
    font-size: 0.9rem;
}

.login-card .form-group { text-align: left; }

.login-card .btn-primary {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
}

/* ===== HERO SECTION (Dashboard) ===== */
.hero {
    background: linear-gradient(135deg, rgba(23,50,79,.98), rgba(42,95,146,.90));
    color: #fff;
    border-radius: 24px;
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.hero h2 { margin: 0 0 8px; font-size: 1.6rem; }
.hero p { margin: 0; color: rgba(255,255,255,.85); font-size: 0.92rem; }

.hero-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-top: 16px;
}

.hero-mini {
    background: rgba(255,255,255,.10);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 14px;
    padding: 12px;
}

.hero-mini .label { color: #f8e5c8; font-size: 0.78rem; font-weight: 800; }
.hero-mini .value { font-size: 1.3rem; font-weight: 900; margin-top: 4px; }

/* ===== ACTIVITY LIST ===== */
.activity-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.activity-item:last-child { border-bottom: none; }

.activity-info { display: flex; flex-direction: column; gap: 2px; }
.activity-info .title { font-weight: 700; font-size: 0.9rem; }
.activity-info .meta { color: var(--muted); font-size: 0.82rem; }

/* ===== RESPONSIVE ===== */
/* ===== MOBILE MENU TOGGLE ===== */
.menu-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1100;
    width: 52px;
    height: 52px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--brand2));
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(139,75,31,.35);
    align-items: center;
    justify-content: center;
    transition: 0.2s ease;
}

.menu-toggle:hover { transform: scale(1.08); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(36,28,21,.45);
    backdrop-filter: blur(3px);
    z-index: 999;
}

@media (max-width: 1024px) {
    .app-layout { grid-template-columns: 1fr; }

    .sidebar {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        z-index: 1000;
        box-shadow: 8px 0 32px rgba(36,28,21,.2);
    }

    .sidebar.open { display: block; }
    .sidebar-overlay.open { display: block; }
    .menu-toggle { display: flex; }

    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .workspace { grid-template-columns: 1fr; }
    .hero-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid { grid-template-columns: 1fr; }
    .topbar { flex-wrap: wrap; }
}

/* ===== VALIDATION ===== */
.field-validation-error {
    color: var(--red);
    font-size: 0.8rem;
    margin-top: 4px;
}

.input-validation-error {
    border-color: var(--red) !important;
}

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(36,28,21,.45);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.loading-overlay.show { display: flex; }

.loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    z-index: 2001;
    overflow: hidden;
    background: rgba(139,75,31,.15);
}

.loading-bar .bar {
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, var(--brand), var(--brand2), var(--brand));
    border-radius: 4px;
    animation: loadingSlide 1.2s ease-in-out infinite;
}

@keyframes loadingSlide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

.loading-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 28px 36px;
    box-shadow: 0 24px 64px rgba(36,28,21,.2);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.loading-spinner {
    width: 44px;
    height: 44px;
    border: 4px solid var(--line);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-card .loading-text {
    font-weight: 800;
    color: var(--brand);
    font-size: 1rem;
}

.loading-card .loading-sub {
    color: var(--muted);
    font-size: 0.85rem;
}

/* ===== MISC ===== */
.text-muted { color: var(--muted); }
.text-brand { color: var(--brand); }
.text-center { text-align: center; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 16px; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 16px; }
.gap-sm { gap: 8px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
