/* =========================================================
   Karang Taruna Muda Berkarya — Admin Panel
   ========================================================= */
:root {
    --primary: #0f766e;
    --primary-600: #0d9488;
    --primary-50: #ecfdf8;
    --accent: #f59e0b;
    --danger: #dc2626;
    --ink: #0b1324;
    --text: #334155;
    --muted: #64748b;
    --line: #e2e8f0;
    --bg: #f4f6fa;
    --card: #ffffff;
    --sidebar: #0b1324;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .07);
    --shadow: 0 12px 32px -14px rgba(15, 23, 42, .25);
    --sidebar-w: 256px;
    --header-h: 64px;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); line-height: 1.55; font-size: 15px; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }
h1, h2, h3 { color: var(--ink); margin: 0; line-height: 1.25; letter-spacing: -.01em; }
code { background: #f1f5f9; padding: .1em .4em; border-radius: 6px; font-size: .9em; }
:focus-visible { outline: 3px solid rgba(13, 148, 136, .45); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.block { display: block; }
.t-right { text-align: right; }
[hidden] { display: none !important; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; padding: .65em 1.2em; border-radius: 10px; font: inherit; font-weight: 600; font-size: .92rem; border: 1px solid transparent; cursor: pointer; transition: background .2s, box-shadow .2s, transform .1s; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-600)); color: #fff; box-shadow: 0 6px 16px -8px rgba(13, 148, 136, .8); }
.btn-primary:hover { color: #fff; filter: brightness(1.05); }
.btn-light { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-light:hover { background: #f8fafc; border-color: #cbd5e1; color: var(--ink); }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: .42em .85em; font-size: .82rem; border-radius: 8px; }
.btn-block { width: 100%; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #fff; display: none; place-items: center; cursor: pointer; padding: 0; }
.icon-btn svg { width: 22px; height: 22px; fill: var(--ink); }

/* ---------- Alerts ---------- */
.alert { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid; font-size: .93rem; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.alert-close { background: none; border: 0; font-size: 1.3rem; line-height: 1; cursor: pointer; color: inherit; opacity: .6; padding: 0 4px; }

/* ---------- Auth ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 10%, #ccfbf1 0, transparent 40%), radial-gradient(circle at 90% 90%, #fde68a 0, transparent 35%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 22px; padding: 32px 28px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.auth-brand strong { display: block; font-size: 1.25rem; color: var(--ink); }
.auth-brand span { color: var(--muted); font-size: .88rem; }
.back-link { display: inline-block; margin-top: 18px; }
.admin-content > .back-link { margin: 0 0 16px; font-weight: 600; }
.input-group { display: flex; gap: 6px; }
.input-group input { flex: 1; min-width: 0; }

/* ---------- Forms ---------- */
.form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; min-width: 0; }
.form-grid > *, .admin-main, .admin-content { min-width: 0; }
select { max-width: 100%; text-overflow: ellipsis; }
.field > span { font-weight: 600; font-size: .88rem; color: var(--ink); }
input[type=text], input[type=password], input[type=search], input[type=number], input[type=date], input[type=tel], input[type=email], select, textarea {
    width: 100%; font: inherit; color: var(--ink); padding: .7em .9em; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--primary-600); box-shadow: 0 0 0 4px rgba(13, 148, 136, .15); }
input:disabled { background: #f1f5f9; color: var(--muted); }
textarea { resize: vertical; min-height: 80px; line-height: 1.6; }
.hint { color: var(--muted); font-size: .8rem; }
.field-error { color: var(--danger); font-size: .82rem; font-weight: 500; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.card-form { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow-sm); }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px 20px; }
.span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 8px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 18px; }
.upload-box { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 16px; border: 2px dashed #cbd5e1; border-radius: 12px; background: #f8fafc; }
.upload-box input[type=file] { font: inherit; font-size: .88rem; width: 100%; min-width: 0; }
.upload-preview { max-height: 180px; width: auto; border-radius: 10px; object-fit: cover; }
.upload-preview.round { width: 120px; height: 120px; border-radius: 50%; }
.char-counter { font-size: .75rem; color: var(--muted); text-align: right; }

.nomor-preview { display: grid; gap: 2px; padding: 16px 18px; border-radius: 12px; background: linear-gradient(135deg, var(--primary), #115e59); color: #ccfbf1; }
.nomor-preview strong { font-size: clamp(1.1rem, 3vw, 1.5rem); color: #fff; font-family: ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: .02em; word-break: break-all; }
.nomor-preview small { opacity: .8; font-size: .78rem; }
.nomor-surat { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-weight: 700; color: var(--primary); background: var(--primary-50); padding: .25em .6em; border-radius: 8px; display: inline-block; word-break: break-all; }
.nomor-surat.sm { font-size: .82rem; }

/* ---------- Layout ---------- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: var(--sidebar); color: #cbd5e1; display: flex; flex-direction: column; z-index: 40; transition: transform .25s ease; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; color: #fff; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.sidebar-brand span { display: flex; flex-direction: column; line-height: 1.15; }
.sidebar-brand strong { font-size: .98rem; }
.sidebar-brand small { color: #5eead4; font-size: .75rem; font-weight: 600; }
.sidebar-nav { padding: 14px 12px; display: grid; gap: 2px; overflow-y: auto; flex: 1; align-content: start; }
.sidebar-nav a { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px; color: #cbd5e1; font-weight: 500; transition: background .2s, color .2s; }
.sidebar-nav a svg { width: 20px; height: 20px; fill: currentColor; opacity: .8; flex: none; }
.sidebar-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar-nav a.active { background: linear-gradient(135deg, rgba(20, 184, 166, .25), rgba(20, 184, 166, .08)); color: #fff; box-shadow: inset 3px 0 0 #2dd4bf; }
.sidebar-foot { padding: 16px 20px; border-top: 1px solid rgba(255, 255, 255, .06); }
.sidebar-foot a { color: #94a3b8; font-size: .88rem; }
.sidebar-backdrop { display: none; }
.admin-main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; height: var(--header-h); display: flex; align-items: center; gap: 14px; padding: 0 24px; background: rgba(255, 255, 255, .85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.topbar-title { font-size: 1.15rem; font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: .9rem; }
.topbar-user form { margin: 0; }
.avatar-sm { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; font-size: .8rem; font-weight: 800; }
.admin-content { padding: 24px; flex: 1; width: 100%; max-width: 1280px; }
.admin-foot { padding: 16px 24px; font-size: .82rem; color: var(--muted); }

/* ---------- Dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat { position: relative; overflow: hidden; display: grid; gap: 6px; padding: 20px; border-radius: var(--radius); background: #fff; border: 1px solid var(--line); color: var(--muted); box-shadow: var(--shadow-sm); transition: transform .2s, box-shadow .2s; }
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat::after { content: ""; position: absolute; right: -24px; top: -24px; width: 96px; height: 96px; border-radius: 50%; opacity: .14; }
.stat strong { font-size: 2rem; color: var(--ink); font-weight: 800; }
.stat span { font-weight: 600; font-size: .88rem; }
.stat-teal::after { background: #14b8a6; } .stat-amber::after { background: #f59e0b; } .stat-indigo::after { background: #6366f1; } .stat-rose::after { background: #f43f5e; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.panel-head h2 { font-size: 1.05rem; }
.panel-head a { font-size: .85rem; font-weight: 600; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); align-items: center; }
.list li:first-child { border-top: 0; }
.list li a { display: grid; gap: 2px; color: var(--ink); min-width: 0; }
.list li a span { font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list li a .badge { justify-self: start; }
.list time { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 28px 10px; }

/* ---------- Toolbar & table ---------- */
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.filter-form { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
.filter-form input[type=search] { max-width: 260px; }
.filter-form select { width: auto; }
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 12px 16px; background: #f8fafc; border-bottom: 1px solid var(--line); }
.table td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafcff; }
.table th.t-right { text-align: right; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.cell-media { display: flex; align-items: center; gap: 12px; }
.cell-media img, .thumb-fallback { width: 52px; height: 40px; border-radius: 8px; object-fit: cover; flex: none; }
.cell-media img.round, .thumb-fallback.round { width: 42px; height: 42px; border-radius: 50%; }
.thumb-fallback { display: grid; place-items: center; background: linear-gradient(135deg, #99f6e4, #fde68a); color: var(--ink); font-weight: 800; font-size: .75rem; }
.cell-media strong { display: block; color: var(--ink); }
.cell-media small { color: var(--muted); font-size: .8rem; }
.badge { display: inline-block; padding: .25em .7em; border-radius: 999px; font-size: .75rem; font-weight: 700; text-transform: capitalize; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-muted { background: #f1f5f9; color: #475569; }
.pagination { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 20px; }
.pagination a { min-width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); color: var(--text); font-weight: 600; background: #fff; }
.pagination a.active, .pagination a:hover { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Admin gallery ---------- */
.admin-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.admin-gallery-item { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.admin-gallery-item img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.agi-body { padding: 12px 14px 14px; display: grid; gap: 4px; }
.agi-body strong { color: var(--ink); font-size: .92rem; }
.agi-body small { color: var(--muted); }
.agi-body .actions { justify-content: flex-start; margin-top: 6px; }

/* ---------- Surat view ---------- */
.surat-view { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
.surat-meta h2 { font-size: 1.15rem; margin: 12px 0 14px; }
.surat-meta dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0 0 18px; font-size: .9rem; }
.surat-meta dt { color: var(--muted); }
.surat-meta dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }
.surat-meta .actions { justify-content: flex-start; }
.surat-pdf { min-width: 0; }

/* ---------- PDF viewer ---------- */
.pdf-viewer { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; box-shadow: var(--shadow-sm); }
.pdf-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #f8fafc; }
.pdf-group { display: flex; align-items: center; gap: 6px; }
.pdf-page input { width: 56px; padding: 6px; text-align: center; }
.pdf-zoom { min-width: 52px; text-align: center; font-weight: 600; font-size: .88rem; }
.pdf-stage { background: #525659; padding: 20px; overflow: auto; min-height: 60vh; max-height: calc(100vh - 160px); text-align: center; }
.pdf-stage canvas { display: inline-block; box-shadow: 0 6px 24px rgba(0, 0, 0, .35); background: #fff; max-width: none; }
.pdf-status { color: #e2e8f0; margin: 20px 0; }

/* ---------- Dialog ---------- */
.confirm-dialog { border: 0; border-radius: 18px; padding: 24px; max-width: 400px; width: calc(100% - 32px); box-shadow: var(--shadow); }
.confirm-dialog::backdrop { background: rgba(11, 19, 36, .5); backdrop-filter: blur(2px); }
.confirm-dialog h3 { margin-bottom: 8px; }
.confirm-dialog p { color: var(--muted); margin: 0 0 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .surat-view { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow); }
    .sidebar-open .sidebar { transform: none; }
    .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(11, 19, 36, .45); z-index: 35; }
    .admin-main { margin-left: 0; }
    .icon-btn { display: grid; }
    .panel-grid { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
    .admin-content { padding: 16px; }
    .topbar { padding: 0 14px; gap: 10px; }
    .hide-sm { display: none; }
    .form-grid { grid-template-columns: minmax(0, 1fr); }
    .card-form { padding: 18px; }
    .filter-form input[type=search], .filter-form select { max-width: none; flex: 1 1 140px; }
    .toolbar > .btn { width: 100%; }
    .stat { padding: 16px; }
    .stat strong { font-size: 1.6rem; }
    /* Tabel -> kartu di layar kecil */
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr { padding: 14px 16px; border-bottom: 1px solid var(--line); }
    .table tr:last-child { border-bottom: 0; }
    .table td { border: 0; padding: 4px 0; }
    .table td[data-label]:not([data-label="Artikel"]):not([data-label="Nama"]):not([data-label="Nomor"])::before { content: attr(data-label) ": "; color: var(--muted); font-size: .8rem; font-weight: 600; }
    .table td.t-right { text-align: left; padding-top: 10px; }
    .table td .actions { justify-content: flex-start; }
    .table td.empty { text-align: center; }
    .pdf-stage { padding: 10px; }
    .pdf-toolbar { justify-content: center; }
    .admin-gallery { grid-template-columns: 1fr 1fr; gap: 10px; }
}
