:root {
    --navy: #1f3f5b;
    --navy-deep: #172f45;
    --blue: #4d91d8;
    --teal: #4f8888;
    --canvas: #d8d9db;
    --panel: #f4f5f6;
    --white: #fff;
    --text: #29323a;
    --muted: #718193;
    --line: #d6dce2;
    --orange: #efa02f;
    --red: #d55d62;
    --green: #30a56d;
    --shadow: 0 16px 44px rgba(20, 42, 60, .16);
    --radius: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--navy); }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: linear-gradient(115deg, #294f70 0%, #4c8186 100%);
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
svg { width: 22px; height: 22px; fill: currentColor; flex: 0 0 auto; }

.app-shell { min-height: 100vh; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: 78px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #eaf2f7;
    background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
    border-right: 1px solid rgba(255,255,255,.08);
    transition: transform .2s ease;
}
.sidebar.hidden { transform: translateX(-100%); border-right: 0; }
.sidebar-toggle {
    width: 46px;
    height: 46px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: #fff;
    background: rgba(255,255,255,.08);
    cursor: pointer;
}
.sidebar-toggle:hover { background: rgba(255,255,255,.16); }
.sidebar-brand {
    height: 65px;
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 0 17px;
    white-space: nowrap;
}
.sidebar-brand span, .brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(145deg, #579de5, #4e8988);
    font-size: 21px;
    font-weight: 900;
    box-shadow: 0 8px 20px rgba(54, 129, 173, .3);
}
.sidebar-brand span { flex: 0 0 44px; }
.sidebar-brand strong { display: none; }
.sidebar nav { padding-top: 18px; display: grid; gap: 5px; }
.nav-link {
    min-width: 210px;
    height: 52px;
    margin: 0 9px;
    padding: 0 17px;
    border: 0;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 19px;
    color: #dbe7ef;
    background: transparent;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}
.nav-link span { opacity: 0; transition: opacity .12s; }
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { color: #fff; background: linear-gradient(90deg, rgba(80,148,215,.38), rgba(79,136,136,.28)); }
.logout-form { margin-top: auto; padding: 0 0 17px; }

.main-content {
    min-height: 100vh;
    margin-left: 78px;
    padding: 0 26px 42px;
    transition: margin-left .2s ease;
}
.sidebar.hidden ~ .main-content { margin-left: 0; }
.topbar {
    min-height: 112px;
    margin: 0 -26px 24px;
    padding: 22px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    color: #fff;
    background: rgba(22, 48, 69, .5);
    border-bottom: 1px solid rgba(255,255,255,.1);
}
.topbar-title { display: flex; align-items: center; gap: 18px; }
.topbar h1 { margin: 2px 0 0; font-size: clamp(27px, 4vw, 38px); line-height: 1.05; }
.eyebrow, .modal-kicker { margin: 0; color: #a9cae1; font-size: 11px; font-weight: 900; letter-spacing: .15em; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    min-height: 132px;
    padding: 19px 21px;
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
    color: #fff;
    box-shadow: var(--shadow);
}
.stat-card::after { content: ""; position: absolute; width: 95px; height: 95px; right: -25px; top: -30px; border-radius: 50%; background: rgba(255,255,255,.12); }
.stat-card span, .stat-card small { display: block; position: relative; z-index: 1; }
.stat-card span { font-size: 14px; font-weight: 750; opacity: .9; }
.stat-card strong { display: block; margin: 6px 0 4px; position: relative; z-index: 1; font-size: 38px; line-height: 1; }
.stat-card small { opacity: .78; }
.stat-card.blue { background: linear-gradient(145deg, #4e94dd, #3f7fbe); }
.stat-card.orange { background: linear-gradient(145deg, #f0aa3f, #da8422); }
.stat-card.red { background: linear-gradient(145deg, #da6a6f, #ba4b53); }
.stat-card.teal { background: linear-gradient(145deg, #5b9997, #397875); }

.panel {
    border-radius: var(--radius);
    overflow: hidden;
    background: rgba(244,245,246,.94);
    box-shadow: var(--shadow);
}
.customer-panel { padding: 20px; }
.narrow-panel { max-width: 860px; padding: 28px; }
.panel-title { margin-bottom: 24px; }
.panel-title h2 { margin: 0 0 7px; font-size: 24px; }
.panel-title p { margin: 0; color: var(--muted); line-height: 1.55; }

.filter-bar {
    display: grid;
    grid-template-columns: minmax(230px, 1fr) 180px 180px auto;
    gap: 12px;
    align-items: center;
    margin-bottom: 18px;
}
.filter-bar input, .filter-bar select, .stack-form input, .stack-form select, .stack-form textarea, .modal-card input, .modal-card select, .modal-card textarea {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text);
    background: #fff;
    outline: none;
    transition: border .15s, box-shadow .15s;
}
.filter-bar input:focus, .filter-bar select:focus, .stack-form input:focus, .stack-form select:focus, .stack-form textarea:focus, .modal-card input:focus, .modal-card select:focus, .modal-card textarea:focus {
    border-color: #5696cf;
    box-shadow: 0 0 0 3px rgba(77,145,216,.14);
}
.search-field { position: relative; }
.search-field svg { position: absolute; left: 13px; top: 12px; color: #8595a3; }
.search-field input { padding-left: 43px; }
.list-heading { padding: 12px 4px; display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; }
.list-heading strong { color: var(--text); }
.customer-list { display: grid; gap: 10px; }
.customer-row {
    display: grid;
    grid-template-columns: minmax(210px, 1.3fr) 150px 150px minmax(360px, auto);
    align-items: center;
    gap: 14px;
    padding: 15px 16px;
    border: 1px solid #dde2e6;
    border-left: 5px solid #7b9bb2;
    border-radius: 13px;
    background: #fff;
    transition: transform .12s, box-shadow .12s;
}
.customer-row:hover { transform: translateY(-1px); box-shadow: 0 8px 25px rgba(37,61,79,.09); }
.customer-row.soon { border-left-color: var(--orange); }
.customer-row.expired { border-left-color: var(--red); background: #fffafa; }
.customer-row.is-paid { border-left-color: var(--green); background: #fbfffd; }
.customer-name-line { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.customer-main h2 { margin: 0; font-size: 17px; line-height: 1.25; }
.customer-main p { margin: 5px 0 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.badge { display: inline-flex; border-radius: 999px; padding: 3px 7px; font-size: 10px; font-weight: 900; text-transform: uppercase; }
.badge.country { color: #315d7d; background: #e2f0fa; }
.paid-badge { color: #197449; background: #daf3e5; }
.customer-meta { display: grid; gap: 2px; }
.customer-meta strong { font-size: 15px; }
.customer-meta small { color: var(--muted); font-size: 12px; }
.meta-label { color: var(--muted); font-size: 10px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.customer-actions { display: flex; justify-content: flex-end; gap: 7px; }
.customer-actions form { display: contents; }
.action-btn {
    min-height: 42px;
    border: 0;
    border-radius: 10px;
    padding: 0 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: #fff;
    text-decoration: none;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
}
.action-btn svg { width: 18px; height: 18px; }
.action-btn.whatsapp { background: #25a968; }
.action-btn.extend { background: #4a87c3; }
.action-btn.paid { background: #e59a2e; }
.action-btn.paid.done { background: #2d9b66; }
.action-btn.edit { width: 42px; padding: 0; color: #455867; background: #e7ebee; }
.action-btn.edit span { display: none; }
.action-btn:disabled { cursor: default; opacity: .8; }
.empty-state { min-height: 170px; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-state strong { margin-bottom: 6px; color: var(--text); font-size: 18px; }

.btn {
    min-height: 46px;
    border: 0;
    border-radius: 10px;
    padding: 0 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}
.btn.primary { color: #fff; background: linear-gradient(135deg, #4e94dc, #477fba); }
.btn.secondary { color: #3d4c58; background: #e3e7ea; }
.btn.danger { margin-right: auto; color: #9a3e45; background: #f7e1e3; }
.btn.whatsapp-btn { color: #fff; background: #25a968; }
.btn.wide { width: 100%; }

.stack-form { display: grid; gap: 16px; }
.stack-form h2 { margin: 8px 0 -4px; font-size: 17px; }
.stack-form label, .modal-card label { display: grid; gap: 7px; color: #3e4c58; font-size: 13px; font-weight: 750; }
.stack-form textarea, .modal-card textarea { resize: vertical; line-height: 1.45; }
.check-row { display: flex !important; align-items: center; grid-template-columns: 20px 1fr; }
.check-row input { width: 18px !important; min-height: 18px !important; }
.field-help { display: block; margin-top: -10px; color: var(--muted); }
.info-box { padding: 14px 16px; border-radius: 10px; color: #426176; background: #e5f0f6; line-height: 1.5; }
.info-box code { padding: 2px 5px; border-radius: 4px; background: rgba(255,255,255,.8); }
.section-rule { margin: 28px 0; border: 0; border-top: 1px solid var(--line); }
.security-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.security-row strong { display: block; }
.security-row p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

.alert { padding: 13px 15px; border-radius: 10px; line-height: 1.4; }
.alert.success { color: #17643f; background: #dff3e8; }
.alert.error { color: #8c3037; background: #fae1e3; }
.app-alert { margin: 0 0 18px; box-shadow: 0 6px 20px rgba(25,50,70,.1); }

.modal {
    width: min(680px, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    padding: 0;
    border: 0;
    border-radius: 18px;
    overflow: auto;
    color: var(--text);
    background: transparent;
    box-shadow: 0 30px 80px rgba(10,24,35,.4);
}
.modal::backdrop { background: rgba(12,30,43,.65); backdrop-filter: blur(3px); }
.modal-card { position: relative; padding: 27px; display: grid; gap: 17px; background: #f6f7f8; }
.modal-card h2 { margin: -8px 38px 0 0; font-size: 24px; }
.modal-close { position: absolute; right: 15px; top: 13px; width: 38px; height: 38px; border: 0; border-radius: 10px; color: #596875; background: #e4e8eb; font-size: 25px; cursor: pointer; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-actions.split-actions { align-items: center; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span-2 { grid-column: span 2; }

.login-body, .install-body { display: grid; min-height: 100vh; place-items: center; padding: 20px; }
.login-card, .install-card { width: min(440px, 100%); padding: 32px; border-radius: 20px; background: rgba(248,249,250,.97); box-shadow: 0 28px 80px rgba(10,28,41,.35); }
.install-card { width: min(560px, 100%); }
.login-card .brand-mark, .install-card .brand-mark { margin-bottom: 18px; }
.login-card h1, .install-card h1 { margin: 0 0 6px; }
.login-card .muted, .install-card .muted { margin: 0 0 24px; }
.muted { color: var(--muted); }

@media (max-width: 1240px) {
    .customer-row { grid-template-columns: minmax(210px, 1fr) 140px 140px; }
    .customer-actions { grid-column: 1 / -1; justify-content: flex-start; padding-top: 2px; }
}

@media (max-width: 900px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .filter-bar { grid-template-columns: 1fr 1fr; }
    .search-field { grid-column: 1 / -1; }
    .customer-row { grid-template-columns: minmax(180px, 1fr) 130px; }
    .customer-meta:nth-of-type(3) { grid-column: 1 / 2; }
}

@media (max-width: 680px) {
    .sidebar { width: 64px; }
    .sidebar-brand { padding-left: 10px; }
    .nav-link { margin-left: 6px; padding-left: 15px; }
    .main-content { margin-left: 64px; padding: 0 10px 24px; }
    .sidebar.hidden ~ .main-content { margin-left: 0; }
    .topbar { min-height: 86px; margin: 0 -10px 13px; padding: 15px 14px; }
    .topbar-title { gap: 12px; }
    .sidebar-toggle { width: 46px; height: 46px; }
    .topbar .eyebrow { display: none; }
    .topbar h1 { font-size: 25px; }
    .topbar .btn { min-height: 42px; padding: 0 12px; font-size: 13px; }
    .stats-grid { gap: 9px; margin-bottom: 12px; }
    .stat-card { min-height: 112px; padding: 15px; border-radius: 13px; }
    .stat-card span { font-size: 12px; }
    .stat-card strong { font-size: 32px; }
    .stat-card small { font-size: 11px; }
    .customer-panel { padding: 11px; }
    .filter-bar { grid-template-columns: 1fr 1fr; gap: 8px; }
    .filter-bar .btn { display: none; }
    .filter-bar input, .filter-bar select { min-height: 43px; font-size: 13px; }
    .list-heading { font-size: 12px; }
    .customer-row { display: grid; grid-template-columns: 1fr auto; gap: 9px; padding: 13px 12px; }
    .customer-main { min-width: 0; }
    .customer-main h2 { font-size: 16px; }
    .customer-meta { text-align: right; }
    .customer-meta:nth-of-type(3) { grid-column: auto; text-align: left; }
    .customer-actions { grid-column: 1 / -1; display: grid; grid-template-columns: 1.35fr 1.2fr 1fr 42px; gap: 6px; }
    .action-btn { min-height: 45px; padding: 0 7px; font-size: 10px; gap: 4px; }
    .action-btn svg { width: 17px; }
    .action-btn.edit { width: auto; }
    .narrow-panel { padding: 18px 15px; }
    .modal { width: calc(100vw - 12px); max-height: calc(100vh - 12px); }
    .modal-card { padding: 22px 16px calc(20px + env(safe-area-inset-bottom)); }
    .modal-actions { display: grid; grid-template-columns: 1fr 1.35fr; }
    .modal-actions.split-actions { grid-template-columns: 1fr 1fr; }
    .modal-actions.split-actions .danger { grid-column: 1 / -1; margin-right: 0; }
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
    .login-card, .install-card { padding: 25px 20px; }
    .security-row { align-items: stretch; flex-direction: column; }
}

@media (max-width: 430px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-card small { display: none; }
    .customer-meta small { font-size: 10px; }
    .customer-actions { grid-template-columns: 1.25fr 1.1fr 1fr 42px; }
    .action-btn span { overflow: hidden; text-overflow: ellipsis; }
}
