/* ============================================================
   Global Variables & Reset
   ============================================================ */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #16161f;
    --bg-card-hover: #1c1c28;
    --bg-input: #0e0e16;
    --border: #2a2a3a;
    --border-focus: #f0b429;
    --text-primary: #e8e8ed;
    --text-secondary: #8888a0;
    --text-muted: #55556a;
    --accent: #f0b429;
    --accent-hover: #f7c948;
    --accent-dim: rgba(240, 180, 41, 0.12);
    --success: #22c55e;
    --success-dim: rgba(34, 197, 94, 0.12);
    --danger: #ef4444;
    --danger-dim: rgba(239, 68, 68, 0.12);
    --info: #3b82f6;
    --info-dim: rgba(59, 130, 246, 0.12);
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
    --font-body: 'DM Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

/* ============================================================
   Layout
   ============================================================ */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 24px 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-logo {
    padding: 0 24px 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.sidebar-logo h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.02em;
}

.sidebar-logo .sub {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 4px;
}

.sidebar-nav { flex: 1; padding: 0 12px; overflow-y: auto; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
    margin-bottom: 2px;
}

.sidebar-nav a:hover { background: var(--bg-card); color: var(--text-primary); }
.sidebar-nav a.active { background: var(--accent-dim); color: var(--accent); }

.sidebar-nav a .icon {
    width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid var(--border);
}

/* Sidebar backdrop for mobile */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 99;
}
.sidebar-backdrop.active { display: block; }

.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 0;
    min-height: 100vh;
}

/* ============================================================
   Top Bar
   ============================================================ */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(12px);
    gap: 12px;
}

.topbar-left {
    display: flex; align-items: center; gap: 12px;
    min-width: 0; /* allow shrink */
}

.topbar-left h2 {
    font-size: 18px; font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right {
    display: flex; align-items: center; gap: 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.badge-admin { background: var(--accent-dim); color: var(--accent); }
.badge-user { background: var(--info-dim); color: var(--info); }
.badge-success { background: var(--success-dim); color: var(--success); }
.badge-danger { background: var(--danger-dim); color: var(--danger); }

/* ============================================================
   Page Content
   ============================================================ */
.page-content { padding: 32px; max-width: 1200px; }

/* ============================================================
   Cards
   ============================================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--transition);
}

.card:hover { border-color: #3a3a4a; }

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.card-header h3 {
    font-size: 15px; font-weight: 600;
}

.card-body { padding: 24px; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

/* ============================================================
   Template Card
   ============================================================ */
.template-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: all var(--transition);
    position: relative;
}

.template-card:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), 0 8px 32px rgba(240, 180, 41, 0.08);
    transform: translateY(-2px);
}

.template-card .tc-mode {
    position: absolute; top: 16px; right: 16px;
}

.template-card .tc-name {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.template-card .tc-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.5;
}

.template-card .tc-meta {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 16px;
    font-family: var(--font-mono);
}

.template-card .tc-actions {
    display: flex; gap: 8px;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    color: #0a0a0f;
}
.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px rgba(240, 180, 41, 0.3);
}

.btn-secondary {
    background: transparent;
    border-color: var(--border);
    color: var(--text-secondary);
}
.btn-secondary:hover:not(:disabled) {
    border-color: var(--text-secondary);
    color: var(--text-primary);
    background: var(--bg-card-hover);
}

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

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; }

/* ============================================================
   Forms
   ============================================================ */
.form-group { margin-bottom: 20px; }

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font-body);
    transition: all var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-control::placeholder { color: var(--text-muted); }

textarea.form-control {
    resize: vertical;
    min-height: 120px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238888a0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ============================================================
   Wallet Button
   ============================================================ */
.wallet-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius);
    background: var(--accent-dim);
    border: 1px solid var(--accent);
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-mono);
    white-space: nowrap;
}

.wallet-btn:hover {
    background: var(--accent);
    color: #0a0a0f;
}

.wallet-btn .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.wallet-btn.disconnected {
    border-color: var(--border);
    background: transparent;
    color: var(--text-secondary);
}

.wallet-btn.disconnected .dot { background: var(--danger); animation: none; }

/* ============================================================
   Chain Selector
   ============================================================ */
.chain-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.chain-selector:hover { border-color: var(--text-muted); }

.chain-selector img { width: 18px; height: 18px; border-radius: 50%; }

/* ============================================================
   Language Toggle
   ============================================================ */
.lang-toggle {
    display: flex;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
}

.lang-toggle a {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    transition: all var(--transition);
}

.lang-toggle a.active {
    background: var(--accent-dim);
    color: var(--accent);
}

.lang-toggle a:hover:not(.active) { color: var(--text-primary); }

/* ============================================================
   Tables
   ============================================================ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 500px; /* force scroll on mobile rather than squish */
}

th, td {
    padding: 12px 16px;
    text-align: left;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

td { color: var(--text-secondary); }

.addr {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-primary);
    word-break: break-all;
    overflow-wrap: anywhere;
}

/* ============================================================
   Toast
   ============================================================ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: calc(100vw - 40px);
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow);
    animation: slideIn 0.3s ease;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 10px;
    word-break: break-word;
}

.toast-success { background: #0d3320; border: 1px solid var(--success); color: var(--success); }
.toast-error { background: #3b1111; border: 1px solid var(--danger); color: var(--danger); }
.toast-info { background: #0c1f3d; border: 1px solid var(--info); color: var(--info); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    padding: 16px;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 { font-size: 16px; }

.modal-close {
    background: none; border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
}

.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* ============================================================
   Airdrop Specific
   ============================================================ */
.airdrop-type-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 24px;
}

.airdrop-type-tabs button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-body);
    min-width: 0;
}

.airdrop-type-tabs button.active {
    background: var(--accent);
    color: #0a0a0f;
}

.estimate-box {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
}

.estimate-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
    gap: 12px;
}

.estimate-row .label { color: var(--text-secondary); white-space: nowrap; }
.estimate-row .value { color: var(--text-primary); font-family: var(--font-mono); font-weight: 600; text-align: right; word-break: break-all; }
.estimate-row.total { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 6px; }
.estimate-row.total .value { color: var(--accent); }

/* ============================================================
   Empty State
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .icon { font-size: 48px; margin-bottom: 16px; opacity: 0.3; }
.empty-state p { font-size: 14px; margin-bottom: 16px; }

/* ============================================================
   Loading Spinner
   ============================================================ */
.spinner {
    width: 20px; height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
    flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Admin Panel
   ============================================================ */
.admin-section {
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
}

.admin-section .card-header {
    background: var(--accent-dim);
}

/* ============================================================
   Mobile Hamburger
   ============================================================ */
.mobile-hamburger {
    display: none;
    background: none; border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    flex-shrink: 0;
}

/* ============================================================
   Responsive — Mobile
   ============================================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }
    .sidebar.open { transform: translateX(0); }

    .main-content { margin-left: 0; }

    .mobile-hamburger { display: block; }

    .page-content { padding: 16px 12px; }

    .card-grid { grid-template-columns: 1fr; }

    .form-row { grid-template-columns: 1fr; }

    .topbar {
        padding: 10px 12px;
        flex-wrap: wrap;
    }

    .topbar-left h2 { font-size: 15px; }

    .topbar-right { gap: 6px; }

    .wallet-btn {
        padding: 6px 10px;
        font-size: 12px;
    }

    .chain-selector {
        padding: 6px 10px;
        font-size: 12px;
    }

    .card-header { padding: 16px; }
    .card-body { padding: 16px; }

    .modal-body { padding: 16px; }
    .modal-header { padding: 16px; }
    .modal-footer { padding: 12px 16px; }

    .template-card { padding: 16px; }
    .template-card .tc-name { font-size: 15px; }

    .empty-state { padding: 40px 16px; }

    .estimate-row { font-size: 12px; }

    /* Button groups wrap */
    .flex.gap-8 { flex-wrap: wrap; }
}

/* Small phones */
@media (max-width: 380px) {
    .topbar-left h2 { display: none; }
    .wallet-btn { font-size: 11px; padding: 5px 8px; }
    .chain-selector { font-size: 11px; padding: 5px 8px; }
    .airdrop-type-tabs button { font-size: 12px; padding: 8px; }
}

/* ============================================================
   Scrollbar
   ============================================================ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   Utility
   ============================================================ */
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-mono { font-family: var(--font-mono); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.hidden { display: none !important; }