:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --border: #e2e5ea;
    --text: #1f2430;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --province: #eef2ff;
    --local: #ecfdf5;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; font-size: 18px; }
.topbar .brand span { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 8px; }
.topbar form { margin: 0; }

.container { max-width: 1080px; margin: 24px auto; padding: 0 24px; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .04em; }
tr:hover td { background: #fafbfc; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.PROVINCE { background: var(--province); color: var(--primary-dark); }
.badge.LOCAL { background: var(--local); color: #047857; }
.badge.inactive { background: #f3f4f6; color: #6b7280; }

.btn {
    display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--card); color: var(--text); font-size: 14px; cursor: pointer; font-weight: 500;
}
.btn:hover { text-decoration: none; background: #f3f4f6; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f3c6c6; background: #fff5f5; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }

.cardhead { display: flex; align-items: center; justify-content: space-between; gap: 10px;
    flex-wrap: wrap; margin-bottom: 14px; }
.cardhead h2 { margin: 0; font-size: 18px; }

/* Key/value table on the detail page */
table.kv { width: 100%; border-collapse: collapse; }
table.kv th { text-align: left; width: 180px; color: var(--muted); font-weight: 600; font-size: 13px;
    padding: 8px 10px; vertical-align: top; border-bottom: 1px solid var(--border); }
table.kv td { padding: 8px 10px; font-size: 14px; border-bottom: 1px solid var(--border); }

/* Expandable region tree */
.tree details > summary { list-style: none; cursor: pointer; padding: 10px 12px; border-radius: 8px;
    background: var(--province); user-select: none; }
.tree details > summary::-webkit-details-marker { display: none; }
.tree .tree-node { display: inline-flex; align-items: center; gap: 8px; }
.tree details > summary::before { content: "▸"; color: var(--muted); margin-right: 8px; display: inline-block;
    transition: transform .15s; }
.tree details[open] > summary::before { transform: rotate(90deg); }
.tree-children { list-style: none; margin: 6px 0 0; padding: 0 0 0 22px; border-left: 2px solid var(--border);
    margin-left: 14px; }
.tree-children li { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 14px; }
.tree-link { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.tree-link:hover { text-decoration: none; color: var(--primary); }

input[type=text], input[type=password], input[type=number], select {
    padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; width: 100%;
    background: #fff;
}

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }

.pagination { display: flex; gap: 8px; align-items: center; margin-top: 16px; justify-content: center; }
.pagination .muted { color: var(--muted); font-size: 14px; }

.login-wrap { max-width: 360px; margin: 80px auto; }
.login-wrap h1 { text-align: center; margin-bottom: 6px; }
.login-wrap .sub { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: 14px; }

/* Horizontal scroll for wide tables on small screens. */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
    html, body { overflow-x: clip; max-width: 100%; }
    .topbar { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px 14px; }
    .topbar > div { flex-wrap: wrap; gap: 10px !important; justify-content: flex-start; }
    .container { margin: 14px auto; padding: 0 12px; }
    .card { padding: 14px; border-radius: 10px; }
    /* Stack every filter control full-width so nothing overflows the row. */
    .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
    .toolbar .grow, .toolbar select, .toolbar .btn { width: 100%; flex: none; }
    table { min-width: 620px; }               /* keep columns readable; .table-scroll scrolls */
    th, td { padding: 8px 10px; font-size: 13px; }
    .login-wrap { margin: 40px auto; padding: 0 16px; }
}
