:root {
    --bg: #f4f7f9;
    --surface: #ffffff;
    --surface-soft: #f0f5f8;
    --line: #d8e2e8;
    --text: #13232f;
    --muted: #547085;
    --brand: #00a3a3;
    --brand-strong: #007f7f;
    --accent: #ff8b38;
    --ok: #0b9f59;
    --warning: #b76d00;
    --danger: #c64343;
    --shadow: 0 18px 50px rgba(18, 47, 70, 0.08);
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
}

* { box-sizing: border-box; }

html { overflow-x: hidden; }
body, input, select, textarea, button { overflow-wrap: anywhere; }

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(1200px 700px at -5% -10%, #d5f1f1 0%, rgba(213, 241, 241, 0) 65%),
        radial-gradient(1100px 650px at 110% -20%, #ffe2cd 0%, rgba(255, 226, 205, 0) 62%),
        var(--bg);
    color: var(--text);
    font-family: "Plus Jakarta Sans", sans-serif;
}

a { color: inherit; }

.shell {
    width: min(980px, calc(100% - 24px));
    margin: 18px auto 26px;
    animation: slideIn .35s ease-out;
}

@keyframes slideIn {
    from { transform: translateY(18px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: linear-gradient(145deg, #ffffff, #f4f9fb);
    box-shadow: var(--shadow);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    font-family: "Sora", sans-serif;
    font-weight: 700;
}

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--brand), var(--brand-strong));
    color: #fff;
    font-size: 16px;
}

.top-actions { display: flex; align-items: center; gap: 10px; }

.top-actions { min-width: 0; flex-wrap: wrap; justify-content: flex-end; }

.pill, .ghost {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    background: #fff;
    overflow-wrap: anywhere;
}

.ghost { text-decoration: none; }

.card {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 16px;
}

.hero-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background:
        linear-gradient(140deg, rgba(0, 163, 163, 0.08), rgba(255, 139, 56, 0.06)),
        #ffffff;
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 14px;
    display: grid;
    gap: 18px;
    grid-template-columns: 1.5fr 1fr;
}

.hero-title {
    margin: 0;
    font-family: "Sora", sans-serif;
    font-size: clamp(24px, 4vw, 34px);
    line-height: 1.08;
}

.hero-sub {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.45;
}

.hero-kpis { display: grid; gap: 10px; }

.mini-kpi {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 10px 12px;
}

.mini-kpi small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.mini-kpi strong { font-family: "Sora", sans-serif; font-size: 18px; font-weight: 700; }

.grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(12, minmax(0, 1fr));
}

.span-12 { grid-column: span 12; }
.span-8 { grid-column: span 8; }
.span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; }
.span-5 { grid-column: span 5; }
.span-4 { grid-column: span 4; }

h1, h2, h3 { font-family: "Sora", sans-serif; margin: 0; }
p { margin: 7px 0 0; color: var(--muted); font-size: 14px; }

.form-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 14px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }

input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    padding: 10px 12px;
    outline: none;
}

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

input:focus, select:focus, textarea:focus {
    border-color: var(--brand);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(0, 163, 163, 0.14);
}

.btn {
    border: 0;
    border-radius: 12px;
    padding: 11px 15px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-strong)); color: #fff; }
.btn-secondary { border: 1px solid var(--line); background: #fff; color: var(--text); }

.btn-icon {
    width: 44px;
    height: 42px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.trash-icon {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.btn-row { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; }

.metrics { margin-top: 14px; display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric { border: 1px solid var(--line); border-radius: var(--radius-md); padding: 12px; background: #fff; }
.metric b { display: block; font-family: "Sora", sans-serif; font-size: 18px; }
.metric span { font-size: 12px; color: var(--muted); }

.status {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    margin-top: 10px;
}

.ok { background: rgba(11, 159, 89, 0.12); color: var(--ok); }
.warn { background: rgba(183, 109, 0, 0.13); color: var(--warning); }
.bad { background: rgba(198, 67, 67, 0.13); color: var(--danger); }

.list { margin-top: 12px; display: grid; gap: 8px; }
.list-item { border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: #fff; }
.list-item strong { display: block; font-size: 14px; }
.list-item small { color: var(--muted); font-size: 12px; }

.permission-grid {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.check-option {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text);
}

.check-option input {
    width: auto;
}

.media-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    margin-top: 10px;
}

.media-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    text-decoration: none;
}

.media-card img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 10px;
    background: var(--surface-soft);
}

.media-card span {
    font-size: 12px;
    color: var(--muted);
}

.map-box {
    height: 320px;
    border: 1px solid var(--line);
    border-radius: 12px;
    margin-top: 12px;
}

.dispatch-form {
    display: grid;
    gap: 6px;
    grid-template-columns: 1fr;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
    font-size: 14px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    max-width: 100%;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.table-scroll table {
    min-width: 680px;
}

.table-scroll table.master-companies-table {
    min-width: 980px;
}

.table-scroll table.master-companies-table thead,
.table-scroll table.master-companies-table tbody {
    min-width: 980px;
}

.table-scroll table.master-companies-table th,
.table-scroll table.master-companies-table td {
    white-space: nowrap;
}

.table-scroll table.master-companies-table td:nth-child(2) {
    white-space: normal;
    min-width: 150px;
}

.table-scroll table.master-companies-table .btn,
.table-scroll table.master-companies-table input,
.table-scroll table.master-companies-table select {
    white-space: nowrap;
}

th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
th { background: #eaf3f7; color: #26455d; font-size: 12px; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }

.flash {
    border-radius: 10px;
    border: 1px solid;
    padding: 10px 12px;
    margin-bottom: 12px;
    font-size: 14px;
}
.flash.success { background: #e8f8ef; color: #0d6a3b; border-color: #b7e7ca; }
.flash.error { background: #fdecec; color: #972727; border-color: #f0bcbc; }

.auth-shell { max-width: 460px; margin: 42px auto; }
.auth-card { padding: 24px; }
.auth-head { text-align: center; margin-bottom: 14px; }
.auth-head h1 { margin: 10px 0 6px; font-size: 28px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; }
.auth-tabs button { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-weight: 700; background: #fff; color: var(--muted); }
.auth-tabs .current { background: linear-gradient(135deg, var(--brand), var(--brand-strong)); color: #fff; border-color: transparent; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(19, 35, 47, 0.48);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 999;
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-card {
    width: min(620px, 100%);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: #fff;
    box-shadow: var(--shadow);
    padding: 16px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.modal-close {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    border-radius: 10px;
    padding: 6px 10px;
    cursor: pointer;
    font-weight: 700;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

body.modal-open {
    overflow: hidden;
}

.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    background: rgba(244, 247, 249, 0.85);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--line);
}

.tray {
    width: min(980px, calc(100% - 8px));
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
    gap: 8px;
}

.tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 6px;
    border-radius: 12px;
    color: #496377;
    text-decoration: none;
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    font-weight: 700;
}

.tab.active {
    border-color: rgba(0, 163, 163, 0.25);
    color: var(--brand-strong);
    background: #ffffff;
    box-shadow: 0 6px 16px rgba(0, 163, 163, 0.16);
}

body.with-nav { padding-bottom: 88px; }

@media (max-width: 980px) {
    .hero-card { grid-template-columns: 1fr; }
    .span-8, .span-7, .span-6, .span-5, .span-4 { grid-column: span 12; }
}

@media (max-width: 900px) {
    .permission-grid {
        grid-template-columns: 1fr;
    }

    .shell { width: calc(100% - 16px); margin: 10px auto 18px; }
    .topbar { border-radius: 14px; padding: 11px 12px; }
    .card, .hero-card { border-radius: 14px; }
    .form-grid, .metrics { grid-template-columns: 1fr; }
    input, select, textarea, button { font-size: 16px; }
    table {
        display: block;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    table thead, table tbody { display: table; width: 100%; min-width: 680px; table-layout: auto; }
    table th, table td { white-space: normal; vertical-align: top; }
    table input, table select { min-width: 84px; }
    .card { min-width: 0; overflow: hidden; }
    .bottom-nav {
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    }

    .tray {
        width: 100%;
        display: flex;
        gap: 6px;
        overflow-x: auto;
        overflow-y: hidden;
        grid-template-columns: none;
        padding-bottom: 2px;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .tray::-webkit-scrollbar {
        display: none;
    }

    .tab {
        min-width: 84px;
        padding: 8px 6px;
        border-radius: 10px;
        gap: 2px;
        font-size: 11px;
        flex: 0 0 auto;
    }

    .tab span:first-child {
        font-size: 13px;
    }

    .tab span:last-child {
        white-space: nowrap;
    }

    body.with-nav {
        padding-bottom: 72px;
    }
}
