/* ==========================================================================
   RanAdmin - UI components (cards, tables, forms, buttons, badges, modal)
   Designed & developed by ufdev
   ========================================================================== */

/* ---------- card ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    min-width: 0;
}
.card-danger { border-color: rgba(248, 113, 113, .3); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card-head h2 { display: flex; align-items: center; gap: 10px; font-size: 15.5px; }
.card-head h2 .icon { color: var(--accent-2); }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.stats-sm { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
@media (min-width: 1700px) { .stats:not(.stats-sm) { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat {
    position: relative; overflow: hidden;
    display: flex; align-items: center; gap: 14px;
    padding: 18px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--border);
}
.stat-icon { position: relative; z-index: 1; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--c-soft); color: var(--c); }
.stat-icon .icon { width: 22px; height: 22px; }
.stat > div:last-child { position: relative; z-index: 1; min-width: 0; }
.stat-label { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); font-size: 12.5px; }
.stat-value { display: block; font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stats-sm .stat-value { font-size: 20px; }
.stat-green { --c: var(--green); --c-soft: var(--green-soft); }
.stat-blue { --c: var(--blue); --c-soft: var(--blue-soft); }
.stat-violet { --c: var(--violet); --c-soft: var(--violet-soft); }
.stat-amber { --c: var(--amber); --c-soft: var(--amber-soft); }
.stat-red { --c: var(--red); --c-soft: var(--red-soft); }
.stat-teal { --c: var(--teal); --c-soft: var(--teal-soft); }

/* ---------- bar chart ---------- */
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; height: 240px; align-items: end; }
.bar-col { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.bar-track { flex: 1; width: 100%; max-width: 44px; display: flex; align-items: flex-end; border-radius: 8px; background: var(--bg-2); }
.bar { width: 100%; height: 0; border-radius: 8px; background: var(--accent); transition: height .7s var(--ease); }
.bar-val { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bar-label { font-size: 11.5px; color: var(--muted); }

/* ---------- toolbar / search / chips ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar > .btn-primary:last-child { margin-left: auto; }
.search {
    display: flex; align-items: center; gap: 8px; flex: 1 1 280px; max-width: 460px;
    padding: 0 6px 0 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-2);
}
.search:focus-within { border-color: var(--accent); }
.search .icon { color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 9px 0; outline: none; }
.filters input[type=date] { width: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 13px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); font-size: 13px; }
.chip:hover { text-decoration: none; border-color: var(--border-strong); color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: #fff; }
.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.note { margin: 0 0 12px; color: var(--text-2); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th {
    position: sticky; top: 0;
    padding: 10px 12px; text-align: left; white-space: nowrap;
    font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
    color: var(--muted); background: var(--surface); border-bottom: 1px solid var(--border);
}
.table th.num { text-align: right; }
.table td { padding: 12px; border-bottom: 1px solid rgba(35, 48, 73, .6); vertical-align: middle; white-space: nowrap; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: rgba(109, 124, 255, .05); }
.table td.empty { text-align: center; color: var(--muted); padding: 34px; }
.actions { text-align: right; white-space: nowrap; }
td.actions > * + * { margin-left: 4px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; background: var(--muted); }
.dot-on { background: var(--green); }
.rank { display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 6px; border-radius: 8px; background: var(--surface-2); font-weight: 600; }
.rank-top { background: var(--amber); color: #1a1205; }
.code { padding: 3px 8px; border-radius: 6px; background: var(--bg-2); border: 1px solid var(--border); color: var(--accent-2); }

/* card-style rows on phones */
@media (max-width: 760px) {
    .table-wrap { margin: 0; padding: 0; overflow: visible; }
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr { margin-bottom: 12px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-2); }
    .table td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; border: 0; white-space: normal; text-align: right; }
    .table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex: none; }
    .table td.actions { justify-content: flex-end; padding-top: 10px; border-top: 1px dashed var(--border); margin-top: 4px; }
    .table td.actions::before { content: none; }
    .table td.empty { justify-content: center; }
    .table td.empty::before { content: none; }
    .truncate, .wrap { max-width: 60%; }
    .hide-mobile { display: none !important; }
}

/* ---------- pager ---------- */
.pager { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 16px; font-size: 13px; }
.pager-links { display: flex; gap: 4px; }
.pager-links a {
    display: grid; place-items: center; min-width: 34px; height: 34px; padding: 0 8px;
    border-radius: 8px; border: 1px solid var(--border); color: var(--text-2);
}
.pager-links a:hover { text-decoration: none; border-color: var(--accent); color: #fff; }
.pager-links a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pager-links .icon { width: 15px; height: 15px; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
    font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap;
    transition: transform .1s, background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn .icon { width: 16px; height: 16px; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn-primary { color: #fff; background: var(--accent); }
.btn-primary:hover { background: #5b6bf0; }
.btn-ghost { color: var(--text-2); background: var(--surface-2); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }
.btn-danger { color: var(--red); background: var(--red-soft); border-color: rgba(248, 113, 113, .3); }
.btn-danger:hover { background: var(--red); color: #1a0606; }
.btn-ok { color: var(--green); background: var(--green-soft); border-color: rgba(52, 211, 153, .3); }
.btn-ok:hover { background: var(--green); color: #04150e; }
.icon-btn {
    display: inline-grid; place-items: center; width: 38px; height: 38px;
    border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn-sm { width: 26px; height: 26px; border-radius: 6px; vertical-align: middle; }
.icon-btn-sm .icon { width: 14px; height: 14px; }

/* ---------- badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
    background: var(--surface-3); color: var(--text-2);
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.span-all { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
input:not([type=checkbox]):not([type=hidden]), select, textarea, .select {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg-2); color: var(--text); outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.search input, .search input:focus { width: auto !important; border: 0 !important; padding: 9px 0 !important; background: transparent !important; box-shadow: none !important; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[readonly], select[disabled] { opacity: .65; }
input[type=date], input[type=datetime-local] { color-scheme: dark; }
.select { width: auto; padding-right: 32px; cursor: pointer; }
.select-sm { padding: 5px 28px 5px 10px; font-size: 12.5px; }
.toolbar .select, .toolbar input[type=date] { width: auto; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; color: var(--text-2); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.input-icon input { padding-left: 40px !important; }
[data-show-when][hidden] { display: none; }

.danger-zone {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    margin-top: 16px; padding: 12px 14px; border-radius: var(--radius-sm);
    border: 1px dashed rgba(248, 113, 113, .35); background: rgba(248, 113, 113, .04); font-size: 13px;
}
.toolbar .danger-zone { margin: 0 0 0 auto; }
.danger-zone input { width: 150px !important; }

/* ---------- alerts ---------- */
.alert {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid; font-weight: 500;
    animation: slide-in .3s var(--ease);
}
.alert span { flex: 1; }
.alert-ok { background: var(--green-soft); border-color: rgba(52, 211, 153, .35); color: var(--green); }
.alert-err { background: var(--red-soft); border-color: rgba(248, 113, 113, .35); color: var(--red); }
.alert-x { background: none; border: 0; color: inherit; cursor: pointer; padding: 2px; opacity: .7; }
.alert-x:hover { opacity: 1; }
@keyframes slide-in { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- list ---------- */
.list { list-style: none; margin: 0; padding: 0; max-height: 640px; overflow-y: auto; }
.list-item {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: var(--radius-sm); color: var(--text-2);
}
.list-item > span:first-child { display: flex; align-items: center; gap: 10px; min-width: 0; }
.list-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.list-item.active { background: var(--accent-soft); color: #fff; }
.list-meta { display: inline-flex; align-items: center; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.list .empty { padding: 20px; text-align: center; color: var(--muted); }

/* ---------- empty state ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 48px 20px; text-align: center; }
.empty-state .icon-xl { color: var(--accent); opacity: .8; }
.empty-state p { margin: 0; }

/* ---------- modal ---------- */
.modal {
    width: min(560px, calc(100vw - 28px)); max-height: calc(100vh - 40px);
    padding: 22px; border: 1px solid var(--border-strong); border-radius: var(--radius);
    background: var(--surface); color: var(--text); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .8);
}
.modal::backdrop { background: rgba(3, 5, 10, .7); backdrop-filter: blur(4px); }
.modal[open] { animation: pop .22s var(--ease); }
.modal h3 { display: flex; align-items: center; gap: 10px; font-size: 16px; margin-bottom: 4px; }
.modal h3 .icon { color: var(--accent-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ---------- toast (copy feedback) ---------- */
.toast {
    position: fixed; right: 20px; bottom: 20px; z-index: 100;
    padding: 10px 16px; border-radius: var(--radius-sm);
    background: var(--surface-3); border: 1px solid var(--border-strong); box-shadow: var(--shadow);
    animation: slide-in .25s var(--ease);
}

@media (max-width: 640px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px; }
    .stat-value { font-size: 20px; }
    .card { padding: 16px; }
    .bars { height: 190px; gap: 6px; }
    .search { max-width: none; }
}
.chips + .note { margin-top: 12px; }
