:root{
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --primary: #0f172a;
    --primary-2: #1e293b;
    --accent: #2563eb;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;

    --radius-sm: 12px;
    --radius: 18px;
    --radius-lg: 24px;

    --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.05);
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 18px 45px rgba(15, 23, 42, 0.12);

    --space-1: 6px;
    --space-2: 10px;
    --space-3: 14px;
    --space-4: 18px;
    --space-5: 24px;
    --space-6: 32px;

    --app-max: 1200px;
    --header-h: 64px;
}

*{
    box-sizing:border-box;
}

html{
    -webkit-text-size-adjust:100%;
    text-size-adjust:100%;
}

body{
    margin:0;
    background:linear-gradient(180deg,#f8fbff 0%, #f4f7fb 100%);
    color:var(--text);
    font-family:Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size:16px;
    line-height:1.45;
}

img{
    max-width:100%;
    display:block;
}

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

button,
input,
select,
textarea{
    font:inherit;
}

button{
    cursor:pointer;
}

.app-shell{
    min-height:100dvh;
    display:flex;
    flex-direction:column;
}

.app-header{
    position:sticky;
    top:0;
    z-index:1000;
    height:calc(var(--header-h) + env(safe-area-inset-top));
    padding-top:env(safe-area-inset-top);
    background:rgba(255,255,255,0.82);
    backdrop-filter:blur(16px);
    -webkit-backdrop-filter:blur(16px);
    border-bottom:1px solid rgba(226,232,240,0.8);
}

.app-header-inner{
    max-width:var(--app-max);
    margin:0 auto;
    height:var(--header-h);
    padding:0 var(--space-4);
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:12px;
}

.app-header-left,
.app-header-right{
    display:flex;
    align-items:center;
    gap:10px;
}

.app-title{
    font-size:18px;
    font-weight:700;
    letter-spacing:-0.02em;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
}

.icon-btn{
    width:44px;
    height:44px;
    border:none;
    border-radius:14px;
    background:var(--surface);
    border:1px solid var(--line);
    box-shadow:var(--shadow-sm);
    display:inline-flex;
    align-items:center;
    justify-content:center;
}

.credit-pill{
    display:inline-flex;
    align-items:center;
    gap:8px;
    padding:10px 14px;
    border-radius:999px;
    background:#eff6ff;
    color:#1d4ed8;
    border:1px solid #bfdbfe;
    font-weight:700;
    white-space:nowrap;
}

.page{
    width:100%;
    max-width:var(--app-max);
    margin:0 auto;
    padding:var(--space-5) var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom));
    flex:1;
}

.card{
    background:rgba(255,255,255,0.9);
    border:1px solid rgba(226,232,240,0.95);
    border-radius:var(--radius-lg);
    box-shadow:var(--shadow);
    padding:var(--space-5);
}

.card + .card{
    margin-top:var(--space-4);
}

.stack{
    display:flex;
    flex-direction:column;
    gap:14px;
}

.grid{
    display:grid;
    gap:16px;
}

.grid-2{
    grid-template-columns:repeat(2,minmax(0,1fr));
}

.grid-3{
    grid-template-columns:repeat(3,minmax(0,1fr));
}

label{
    display:block;
    font-size:14px;
    font-weight:600;
    color:var(--text);
    margin-bottom:8px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea{
    width:100%;
    min-height:48px;
    border:1px solid var(--line);
    background:#fff;
    color:var(--text);
    border-radius:16px;
    padding:12px 14px;
    outline:none;
    transition:border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}

input:focus,
select:focus,
textarea:focus{
    border-color:#93c5fd;
    box-shadow:0 0 0 4px rgba(37,99,235,.12);
}

.btn{
    min-height:46px;
    padding:12px 16px;
    border-radius:16px;
    border:1px solid transparent;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    gap:8px;
    font-weight:700;
    transition:transform .15s ease, opacity .15s ease, box-shadow .2s ease;
}

.btn:hover{
    transform:translateY(-1px);
}

.btn.primary{
    background:linear-gradient(135deg,#2563eb,#1d4ed8);
    color:#fff;
    box-shadow:0 10px 24px rgba(37,99,235,.25);
}

.btn.secondary{
    background:#fff;
    color:var(--text);
    border-color:var(--line);
}

.btn.danger{
    background:#fff;
    color:var(--danger);
    border-color:#fecaca;
}

.actions{
    display:flex;
    gap:10px;
    flex-wrap:wrap;
}

.flash{
    padding:14px 16px;
    border-radius:16px;
    font-weight:600;
    border:1px solid transparent;
}

.flash-success{
    background:#f0fdf4;
    color:#166534;
    border-color:#bbf7d0;
}

.flash-error{
    background:#fef2f2;
    color:#991b1b;
    border-color:#fecaca;
}

.flash-warning{
    background:#fff7ed;
    color:#9a3412;
    border-color:#fed7aa;
}

.muted{
    color:var(--muted);
}

.region-grid,
.admin-grid{
    display:grid;
    gap:16px;
    grid-template-columns:repeat(auto-fit,minmax(220px,1fr));
}

.region-card{
    background:linear-gradient(180deg,#ffffff 0%, #f8fafc 100%);
    border:1px solid var(--line);
    border-radius:22px;
    padding:18px;
    min-height:110px;
    box-shadow:var(--shadow-sm);
    display:flex;
    flex-direction:column;
    justify-content:center;
    gap:8px;
    transition:transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.region-card:hover{
    transform:translateY(-2px);
    box-shadow:var(--shadow);
    border-color:#cbd5e1;
}

.table-wrap{
    overflow:auto;
    border:1px solid var(--line);
    border-radius:20px;
    background:#fff;
}

table{
    width:100%;
    border-collapse:collapse;
    min-width:720px;
}

th,
td{
    padding:14px 16px;
    border-bottom:1px solid var(--line);
    text-align:left;
    vertical-align:middle;
}

th{
    background:#f8fafc;
    color:#334155;
    font-size:14px;
}

.viewer-card{
    padding:0;
    overflow:hidden;
}

.viewer-top{
    display:flex;
    justify-content:space-between;
    gap:16px;
    align-items:flex-start;
    padding:18px;
    border-bottom:1px solid var(--line);
    background:rgba(248,250,252,.9);
}

.zoom-toolbar{
    display:flex;
    gap:10px;
    padding:14px 18px;
    border-bottom:1px solid var(--line);
    background:#fff;
}

.viewer-stage{
    background:#0f172a;
    min-height:calc(100dvh - 220px);
    display:flex;
    align-items:center;
    justify-content:center;
    overflow:auto;
    padding:16px;
}

.viewer-image{
    max-width:100%;
    height:auto;
    border-radius:12px;
    box-shadow:0 20px 50px rgba(0,0,0,.28);
}

.pdf-inline-wrap{
    width:100%;
    height:calc(100dvh - 140px);
    min-height:72dvh;
    background:#fff;
}

.pdf-inline-frame{
    width:100%;
    height:100%;
    border:0;
    display:block;
}

.drawer-backdrop{
    position:fixed;
    inset:0;
    background:rgba(15,23,42,.35);
    opacity:0;
    visibility:hidden;
    transition:.2s ease;
    z-index:1200;
}

.drawer{
    position:fixed;
    top:0;
    left:0;
    width:min(86vw,360px);
    height:100dvh;
    padding:calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
    background:#fff;
    box-shadow:24px 0 60px rgba(15,23,42,.18);
    transform:translateX(-100%);
    transition:transform .22s ease;
    z-index:1300;
    display:flex;
    flex-direction:column;
    gap:12px;
}

.drawer.open{
    transform:translateX(0);
}

.drawer-backdrop.open{
    opacity:1;
    visibility:visible;
}

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

.drawer-title{
    font-size:18px;
    font-weight:800;
}

.drawer-nav{
    display:flex;
    flex-direction:column;
    gap:8px;
}

.drawer-link{
    min-height:48px;
    padding:12px 14px;
    border-radius:16px;
    display:flex;
    align-items:center;
    background:#f8fafc;
    border:1px solid transparent;
    font-weight:600;
}

.drawer-link:hover{
    border-color:var(--line);
    background:#fff;
}

.drawer-footer{
    margin-top:auto;
    padding-top:16px;
    border-top:1px solid var(--line);
    display:flex;
    flex-direction:column;
    gap:12px;
}

.mobile-credit{
    display:none;
}

.auth-page .page{
    display:grid;
    place-items:center;
    min-height:calc(100dvh - var(--header-h));
}

.auth-card,
.narrow{
    width:min(100%, 520px);
    margin-inline:auto;
}

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

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

    .actions{
        width:100%;
    }

    .actions .btn{
        flex:1 1 100%;
    }
}

@media (max-width: 768px){
    .app-header-inner{
        padding:0 12px;
    }

    .page{
        padding:16px 12px calc(24px + env(safe-area-inset-bottom));
    }

    .card{
        padding:16px;
        border-radius:20px;
    }

    .credit-pill.desktop-credit{
        display:none;
    }

    .mobile-credit{
        display:inline-flex;
    }

    .table-wrap{
        border-radius:16px;
    }

    .pdf-inline-wrap{
        height:calc(100dvh - 110px);
        min-height:calc(100dvh - 110px);
    }

    .viewer-stage{
        min-height:calc(100dvh - 180px);
        padding:10px;
    }
}