/* ============================================
   Fikua Lab — Issuer
   Light/Dark theme with Fikua Lab design system
   ============================================ */

:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --border: #e2e8f0;
    --text: #334155;
    --text-muted: #64748b;
    --heading: #0f172a;
    --accent: #2A9D8F;
    --accent-hover: #238578;
    --accent-subtle: rgba(42, 157, 143, 0.08);
    --primary: #3b82f6;
    --primary-subtle: rgba(59, 130, 246, 0.1);
    --success: #10b981;
    --success-subtle: rgba(16, 185, 129, 0.1);
    --warning: #f59e0b;
    --warning-subtle: rgba(245, 158, 11, 0.1);
    --danger: #ef4444;
    --danger-subtle: rgba(239, 68, 68, 0.1);
    --nav-bg: rgba(255, 255, 255, 0.85);
    --btn-accent-text: #fff;
    --radius: 8px;
    --radius-lg: 12px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
    --max-width: 960px;
}

[data-theme="dark"] {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-hover: #22263a;
    --border: #2a2e3f;
    --text: #e1e4ed;
    --text-muted: #8b90a0;
    --heading: #e2e8f0;
    --accent: #2dd4bf;
    --accent-hover: #5eead4;
    --accent-subtle: rgba(45, 212, 191, 0.1);
    --primary: #4f8ff7;
    --primary-subtle: rgba(79, 143, 247, 0.15);
    --success: #34d399;
    --success-subtle: rgba(52, 211, 153, 0.15);
    --warning: #fbbf24;
    --warning-subtle: rgba(251, 191, 36, 0.15);
    --danger: #f87171;
    --danger-subtle: rgba(248, 113, 113, 0.15);
    --nav-bg: rgba(15, 17, 23, 0.9);
    --btn-accent-text: #0f1117;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background 0.3s, color 0.3s;
}

a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { color: var(--heading); line-height: 1.3; }

/* --- Theme Toggle --- */
.theme-toggle {
    background: none; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 0.35rem; cursor: pointer; color: var(--text-muted);
    display: inline-flex; align-items: center; justify-content: center;
    transition: color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { color: var(--heading); border-color: var(--text-muted); }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* --- Nav --- */
.nav {
    position: sticky; top: 0; z-index: 100;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    transition: background 0.3s, border-color 0.3s;
}
.nav-inner {
    max-width: var(--max-width); margin: 0 auto; padding: 0.75rem 1.5rem;
    display: flex; justify-content: space-between; align-items: center;
}
.nav-brand {
    display: flex; align-items: center; gap: 0.6rem;
    color: var(--heading); font-weight: 600; font-size: 0.95rem;
}
.nav-logo {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; background: var(--accent); color: #fff;
    border-radius: 6px; font-weight: 700; font-size: 0.85rem;
}
.nav-links { display: flex; align-items: center; gap: 0.75rem; }
.nav-label {
    font-size: 0.8rem; font-family: var(--mono); color: var(--text-muted);
    background: var(--surface); padding: 0.2rem 0.6rem; border-radius: 4px;
    border: 1px solid var(--border);
}

/* --- Main --- */
main {
    max-width: var(--max-width); margin: 0 auto; padding: 1.5rem 1.5rem;
}

/* --- Tabs --- */
.tabs {
    display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem;
}
.tab {
    font-family: var(--font); font-size: 0.875rem; font-weight: 500;
    padding: 0.6rem 1.25rem; background: none; border: none; cursor: pointer;
    color: var(--text-muted); border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--heading); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* --- Steps --- */
.step { margin-bottom: 1.5rem; }
.step-header {
    display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.25rem;
}
.step-header h2 { font-size: 1.125rem; font-weight: 600; }
.step-sub { color: var(--text-muted); font-size: 0.85rem; }
.step-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
    background: var(--accent-subtle); color: var(--accent);
}
.step-icon-success { background: var(--success-subtle); color: var(--success); }

/* --- Buttons --- */
.btn {
    font-family: var(--font); font-size: 0.8125rem;
    padding: 0.4rem 0.85rem; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text); cursor: pointer;
    transition: all 0.15s; display: inline-flex; align-items: center; gap: 0.5rem;
}
.btn:hover { background: var(--surface-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-accent {
    background: var(--accent); border-color: var(--accent);
    color: var(--btn-accent-text); font-weight: 600;
}
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-sm { font-size: 0.75rem; padding: 0.3rem 0.65rem; }
.btn-icon {
    background: none; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 0.3rem; cursor: pointer; color: var(--text-muted);
    display: inline-flex; align-items: center; justify-content: center;
    transition: color 0.15s, border-color 0.15s;
}
.btn-icon:hover { color: var(--heading); border-color: var(--text-muted); }

/* --- Spinner --- */
.spinner {
    width: 32px; height: 32px; border: 3px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: spin 0.8s linear infinite; margin: 0 auto;
}
.spinner-wrap { padding: 3rem 0; text-align: center; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Config Grid --- */
.config-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.75rem;
}
.config-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 1rem 1.25rem; cursor: pointer; transition: all 0.15s;
    display: flex; flex-direction: column; gap: 0.35rem;
}
.config-card:hover { border-color: var(--accent); background: var(--accent-subtle); }
.config-card-header { display: flex; justify-content: space-between; align-items: center; }
.config-card-name { font-weight: 600; font-size: 0.9rem; color: var(--heading); }
.config-card-desc { font-size: 0.8rem; color: var(--text-muted); }
.config-card-id { font-size: 0.7rem; font-family: var(--mono); color: var(--text-muted); word-break: break-all; }

/* --- Badges --- */
.badge {
    font-size: 0.7rem; font-family: var(--mono); font-weight: 600;
    padding: 0.1rem 0.45rem; border-radius: 4px; white-space: nowrap;
}
.badge-format { background: var(--primary-subtle); color: var(--primary); }
.badge-pending { background: var(--warning-subtle); color: var(--warning); }
.badge-offer_created { background: var(--primary-subtle); color: var(--primary); }
.badge-issued { background: var(--success-subtle); color: var(--success); }
.badge-failed { background: var(--danger-subtle); color: var(--danger); }
.badge-draft { background: var(--primary-subtle); color: var(--primary); }

/* --- Form --- */
.issuance-form { display: flex; flex-direction: column; gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group label { font-size: 0.8rem; font-weight: 500; color: var(--text-muted); }
.form-group input {
    font-family: var(--font); font-size: 0.875rem; padding: 0.5rem 0.75rem;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text); transition: border-color 0.15s;
}
.form-group input:focus { outline: none; border-color: var(--accent); }
.form-actions {
    display: flex; justify-content: space-between; align-items: center;
    padding-top: 0.5rem; border-top: 1px solid var(--border);
}
.form-defaults-wrap { display: flex; justify-content: flex-end; margin-bottom: 0.25rem; }

/* --- Delivery method selector --- */
.delivery-method {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.5rem 0; margin-bottom: 0.25rem;
}
.delivery-label {
    font-size: 0.8rem; font-weight: 500; color: var(--text-muted);
}
.delivery-options { display: flex; gap: 0.35rem; }
.delivery-option { cursor: pointer; }
.delivery-option input { display: none; }
.delivery-pill {
    display: inline-flex; align-items: center; gap: 0.3rem;
    font-size: 0.78rem; font-weight: 500; padding: 0.3rem 0.7rem;
    border: 1px solid var(--border); border-radius: 999px;
    color: var(--text-muted); background: var(--surface); transition: all 0.15s;
}
.delivery-option input:checked + .delivery-pill {
    border-color: var(--accent); color: var(--accent); background: var(--accent-subtle);
}
.delivery-pill:hover { border-color: var(--accent); }

/* --- Result --- */
.result-content {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 1.5rem; text-align: center;
}
.result-qr { margin-bottom: 1rem; }
.result-qr canvas { border-radius: var(--radius); }
.result-uri {
    font-family: var(--mono); font-size: 0.75rem; color: var(--text-muted);
    word-break: break-all; padding: 0.75rem; background: var(--bg);
    border: 1px solid var(--border); border-radius: var(--radius);
    margin: 0.75rem 0; cursor: pointer; transition: border-color 0.15s;
}
.result-uri:hover { border-color: var(--accent); }
.result-tx-code {
    display: inline-flex; align-items: center; gap: 0.5rem;
    font-size: 1.5rem; font-family: var(--mono); font-weight: 700; letter-spacing: 0.3em;
    background: var(--warning-subtle); color: var(--warning);
    padding: 0.5rem 1.25rem; border-radius: var(--radius-lg); margin: 1rem 0;
}
.result-tx-label { font-size: 0.75rem; font-weight: 500; letter-spacing: normal; }
.result-deeplink { margin-top: 0.75rem; }
.result-draft { padding: 1rem 0; }
.result-draft-icon { margin-bottom: 1rem; }
.result-draft-title { font-size: 1.25rem; font-weight: 700; color: var(--heading); margin-bottom: 0.25rem; }
.result-draft-desc { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.result-draft-email {
    font-family: var(--mono); font-size: 0.95rem; font-weight: 600; color: var(--accent);
    background: var(--accent-subtle); padding: 0.4rem 1rem; border-radius: var(--radius);
    display: inline-block; margin-bottom: 0.75rem;
}
.result-draft-hint { font-size: 0.8rem; color: var(--text-muted); max-width: 360px; margin: 0 auto; }
.result-actions { margin-top: 1rem; }

/* --- Table --- */
.records-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.records-toolbar h2 { font-size: 1.125rem; font-weight: 600; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.table {
    width: 100%; border-collapse: collapse; font-size: 0.8125rem;
}
.table th {
    text-align: left; padding: 0.6rem 0.75rem; font-weight: 600; font-size: 0.75rem;
    color: var(--text-muted); background: var(--surface); border-bottom: 1px solid var(--border);
    text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap;
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--heading); }
.table th.active-sort { color: var(--accent); }
.sort-arrow { font-size: 0.65rem; margin-left: 0.2rem; }
.table td {
    padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle;
}
.table tbody tr { cursor: pointer; transition: background 0.1s; }
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr:last-child td { border-bottom: none; }
.table .cell-id { font-family: var(--mono); font-size: 0.75rem; color: var(--text-muted); }
.table .cell-type { max-width: 200px; }

.empty-state { color: var(--text-muted); font-size: 0.85rem; padding: 2rem; text-align: center; }

/* --- Pagination --- */
.pagination {
    display: flex; justify-content: center; align-items: center; gap: 0.75rem;
    margin-top: 1rem;
}
.page-info { font-size: 0.8rem; color: var(--text-muted); }

/* --- Dialog --- */
.record-dialog {
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    background: var(--bg); color: var(--text); padding: 0;
    max-width: 560px; width: calc(100% - 2rem);
    box-shadow: 0 16px 40px rgba(0,0,0,0.15);
}
.record-dialog::backdrop { background: rgba(0,0,0,0.4); }
.dialog-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.dialog-header h3 { font-size: 1rem; font-weight: 600; }
.dialog-content { padding: 1.25rem; max-height: 70vh; overflow-y: auto; }
.dialog-row {
    display: flex; justify-content: space-between; padding: 0.4rem 0;
    border-bottom: 1px solid var(--border); gap: 1rem;
}
.dialog-row:last-child { border-bottom: none; }
.dialog-label { font-size: 0.8rem; color: var(--text-muted); flex-shrink: 0; }
.dialog-value {
    font-size: 0.8rem; font-family: var(--mono); text-align: right;
    word-break: break-all;
}
.dialog-section { font-size: 0.8rem; font-weight: 600; color: var(--heading); margin: 0.75rem 0 0.25rem; }

.hidden { display: none; }

/* --- Responsive --- */
@media (max-width: 768px) {
    main { padding: 1rem; }
    .config-grid { grid-template-columns: 1fr; }
    .form-actions { flex-direction: column; gap: 0.75rem; align-items: stretch; }
    .form-actions .btn-accent { justify-content: center; }
}

@media (max-width: 480px) {
    .nav-name { display: none; }
    .nav-inner { padding: 0.6rem 1rem; }
    .table { font-size: 0.75rem; }
    .table th, .table td { padding: 0.45rem 0.5rem; }
    .result-tx-code { font-size: 1.2rem; }
}
