:root {
    --bg: #f5f6fa;
    --card: #ffffff;
    --text: #1a1f2c;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #5b6cff;
    --primary-dark: #4051d8;
    --ok: #10b981;
    --err: #ef4444;
    --warn: #f59e0b;
    --shadow: 0 1px 2px rgba(20,25,40,.04), 0 4px 14px rgba(20,25,40,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-size: 15px; line-height: 1.5; }

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

h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.err { color: var(--err); }
.grow { flex: 1 1 auto; }

/* Topbar */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 24px; background: #fff; border-bottom: 1px solid var(--border);
}
.topbar.admin { background: #1a1f2c; color: #fff; }
.topbar.admin .brand { color: #fff; }
.topbar.admin a.btn.ghost { color: #fff; border-color: rgba(255,255,255,.2); }
.brand { font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

/* Container */
.container { max-width: 1100px; margin: 24px auto; padding: 0 24px; display: flex; flex-direction: column; gap: 16px; }
.container.narrow { max-width: 560px; }

/* Auth */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.auth-card { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 32px; width: 100%; max-width: 420px; }
.auth-card h1 { margin-bottom: 8px; }
.auth-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.auth-card label { font-size: 13px; color: var(--muted); }

/* Card */
.card {
    background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
    padding: 20px 22px;
}
.alert-card {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    border-left: 4px solid var(--primary);
}
.alert-card h3 { margin-bottom: 4px; }
.alert-card p { margin: 0; }
.highlight-card { border-left: 4px solid var(--warn); }

/* Inputs / buttons */
input[type="text"], input[type="email"], input[type="number"], input[type="date"], input:not([type]), select, textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
    background: #fff; color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(91,108,255,.3); border-color: var(--primary); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: 1px solid var(--border); background: #fff; color: var(--text);
    padding: 9px 16px; border-radius: 8px; font: inherit; cursor: pointer; font-weight: 500;
    transition: all .15s;
}
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn.danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Alert */
.alert { padding: 10px 14px; border-radius: 8px; margin-top: 12px; font-size: 14px; }
.alert.ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert.err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { background: var(--card); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 600; margin-top: 4px; }
.stat-sub { margin-top: 2px; }
.stat.highlight { border-left: 4px solid var(--warn); }

@media (max-width: 720px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.data-table th, .data-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafafa; }
.data-table.small th, .data-table.small td { padding: 7px 10px; font-size: 13px; }
.data-table tbody tr:last-child td { border-bottom: 0; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-succeeded { background: #ecfdf5; color: #065f46; }
.badge-processing { background: #eff6ff; color: #1e3a8a; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-requires_action, .badge-requires_payment_method { background: #fef2f2; color: #991b1b; }

/* Admin layout */
.admin-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
.sidebar { position: sticky; top: 16px; }
.main-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (max-width: 860px) { .admin-layout { grid-template-columns: 1fr; } .sidebar { position: static; } }

.customer-list { list-style: none; padding: 0; margin: 12px 0 0; }
.customer-list li a { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 8px; color: var(--text); }
.customer-list li a:hover { background: #f3f4f6; text-decoration: none; }
.customer-list li.active a { background: #eef0ff; color: var(--primary-dark); font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.off { background: #d1d5db; }

.inline-form { display: flex; gap: 8px; margin-top: 8px; }
.inline-form input { flex: 1; }

.row-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-top: 8px; }
.row-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.row-form input { min-width: 140px; }
.row-form.compact label { gap: 2px; }

.op-block { padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; }
.op-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.op-totals { font-size: 14px; }

/* Spinner */
.spinner {
    width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
