/* ================================================================
   PPM Billing Calculator — Shared Stylesheet
   ================================================================ */

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
    --bg-body: linear-gradient(180deg, #0f172a 0%, #111827 45%, #0f172a 100%);
    --bg-container: rgba(15, 23, 42, 0.92);
    --border-color: rgba(148, 163, 184, 0.15);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --bg-card: rgba(31, 41, 55, 0.95);
    --bg-input: rgba(15, 23, 42, 0.95);
    --bg-tab: rgba(31, 41, 55, 0.6);
    --bg-hover: rgba(148, 163, 184, 0.08);
    --purple: #7c3aed;
    --purple-hover: #9333ea;
    --green: #059669;
    --green-hover: #10b981;
    --green-soft: rgba(34, 197, 94, 0.12);
    --green-soft-border: rgba(34, 197, 94, 0.25);
    --green-text: #86efac;
    --red-soft: rgba(239, 68, 68, 0.12);
    --red-soft-border: rgba(239, 68, 68, 0.25);
    --red-text: #fca5a5;
    --light-green-text: #16a34a;
    --light-red-text: #dc2626;
}

[data-theme="light"] {
    --bg-body: linear-gradient(180deg, #f1f5f9 0%, #e2e8f0 45%, #f1f5f9 100%);
    --bg-container: rgba(255, 255, 255, 0.95);
    --border-color: rgba(100, 116, 139, 0.2);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --bg-card: rgba(241, 245, 249, 0.95);
    --bg-input: rgba(255, 255, 255, 0.95);
    --bg-tab: rgba(226, 232, 240, 0.8);
    --bg-hover: rgba(100, 116, 139, 0.1);
    --green-text: #16a34a;
    --red-text: #dc2626;
}

/* ── Reset & Base ──────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 32px;
    transition: background 0.3s, color 0.3s;
}

/* ── Container ─────────────────────────────────────────────── */
.container {
    width: min(1100px, 100%);
    margin: 0 auto;
    background: var(--bg-container);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.45);
    padding: 32px;
    transition: background 0.3s, border-color 0.3s;
}

/* ── Typography ────────────────────────────────────────────── */
h1 {
    margin: 0 0 8px;
    font-size: clamp(1.5rem, 2vw, 2rem);
    letter-spacing: -0.03em;
}

p.subtitle {
    margin: 0 0 24px;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ── User Bar ──────────────────────────────────────────────── */
.user-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 10px 18px;
    margin-bottom: 24px;
    font-size: 0.9rem;
    transition: background 0.3s, border-color 0.3s;
}

.user-bar .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-bar .badge {
    background: var(--purple);
    border-radius: 20px;
    padding: 2px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #f8fafc;
}

.user-bar .logout-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    transition: border-color 0.2s, color 0.2s;
}

.user-bar .logout-link:hover {
    border-color: #ef4444;
    color: var(--red-text);
}

/* ── Logo ──────────────────────────────────────────────────── */
.logo-text {
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: 0.08em;
    color: var(--purple);
    user-select: none;
}

/* ── Theme Toggle ──────────────────────────────────────────── */
.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s;
    color: var(--text-primary);
    padding: 0;
    line-height: 1;
}

.theme-toggle:hover {
    background: var(--bg-hover);
}

/* ── Tabs ──────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    background: var(--bg-tab);
    border-radius: 14px;
    padding: 4px;
}

.tab-btn {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    padding: 12px 20px;
    border-radius: 11px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    text-decoration: none;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.tab-btn.active {
    background: var(--purple);
    color: #f8fafc;
}

/* ── Messages ──────────────────────────────────────────────── */
.message {
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.message.success {
    background: var(--green-soft);
    border: 1px solid var(--green-soft-border);
    color: var(--green-text);
}

[data-theme="light"] .message.success {
    color: var(--light-green-text);
}

.message.error {
    background: var(--red-soft);
    border: 1px solid var(--red-soft-border);
    color: var(--red-text);
}

[data-theme="light"] .message.error {
    color: var(--light-red-text);
}

/* ── Form Elements ─────────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 14px;
    background: rgba(15, 23, 42, 0.82);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border-color);
    margin-bottom: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.field select,
.field input {
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-primary);
    padding: 10px 12px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
}

.field select:focus,
.field input:focus {
    border-color: var(--purple);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}

.field select option:disabled {
    color: #475569;
}

.field .hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ── Rp Prefix ─────────────────────────────────────────────── */
.rp-prefix {
    position: relative;
}

.rp-prefix input {
    padding-left: 36px;
}

.rp-prefix span {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #64748b;
    font-size: 0.9rem;
    pointer-events: none;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    border: none;
    border-radius: 12px;
    padding: 11px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--purple);
    color: #f8fafc;
}

.btn-primary:hover {
    background: var(--purple-hover);
}

.btn-submit {
    background: var(--green);
    color: #f8fafc;
    padding: 14px 32px;
    font-size: 1rem;
}

.btn-submit:hover {
    background: var(--green-hover);
}

.btn-danger {
    background: var(--red-soft);
    color: var(--red-text);
    border: 1px solid var(--red-soft-border);
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
}

.btn-edit,
.btn-del {
    padding: 4px 10px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.78rem;
    transition: all 0.2s;
    display: inline-block;
}

.btn-edit {
    background: rgba(52, 211, 153, 0.12);
    color: #6ee7b7;
    border: 1px solid rgba(52, 211, 153, 0.2);
}

.btn-edit:hover {
    background: rgba(52, 211, 153, 0.22);
}

.btn-del {
    background: var(--red-soft);
    color: var(--red-text);
    border: 1px solid var(--red-soft-border);
}

.btn-del:hover {
    background: rgba(239, 68, 68, 0.25);
}

.btn-update {
    background: rgba(124, 58, 237, 0.15);
    color: #a78bfa;
    border: 1px solid rgba(124, 58, 237, 0.2);
    padding: 6px 14px;
    font-size: 0.78rem;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-update:hover {
    background: rgba(124, 58, 237, 0.25);
}

.action-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 8px;
}

/* ── Result Card ───────────────────────────────────────────── */
.result-card {
    margin-top: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 24px;
    color: var(--text-primary);
}

.result-card h2 {
    margin-top: 0;
    color: var(--text-primary);
    font-size: 1.2rem;
}

.result-card p {
    margin: 10px 0;
    line-height: 1.6;
    color: var(--text-primary);
}

.result-card p strong {
    color: var(--text-secondary);
}

/* ── Table ─────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    margin-top: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead th {
    text-align: left;
    padding: 12px 14px;
    background: var(--bg-tab);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

thead th:first-child {
    border-radius: 12px 0 0 0;
}

thead th:last-child {
    border-radius: 0 12px 0 0;
}

tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.06);
    white-space: nowrap;
    vertical-align: middle;
}

tbody tr:hover {
    background: rgba(124, 58, 237, 0.04);
}

tbody tr:last-child td:first-child {
    border-radius: 0 0 0 12px;
}

tbody tr:last-child td:last-child {
    border-radius: 0 0 12px 0;
}

.empty-msg {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

/* ── Status Badges ─────────────────────────────────────────── */
.status-badge {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-pending {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}

.status-approved {
    background: rgba(52, 211, 153, 0.15);
    color: #34d399;
}

.status-rejected {
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
}

/* ── Approval Select ───────────────────────────────────────── */
.status-select {
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-primary);
    padding: 6px 10px;
    font-size: 0.8rem;
    outline: none;
    cursor: pointer;
}

.status-select:focus {
    border-color: var(--purple);
}

/* ── Total Cell ────────────────────────────────────────────── */
.total-cell {
    color: #86efac;
    font-weight: 600;
    font-style: italic;
}

/* ── Edit Form ─────────────────────────────────────────────── */
.edit-form {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 24px;
    margin-bottom: 24px;
}

.edit-form h3 {
    margin: 0 0 16px;
    color: var(--text-primary);
}

.edit-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 14px;
}

.edit-grid .field input,
.edit-grid .field select {
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-primary);
    padding: 10px 12px;
    font-size: 0.9rem;
    outline: none;
    width: 100%;
}

.edit-grid .field input:focus,
.edit-grid .field select:focus {
    border-color: var(--purple);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}

/* ── Login Page ────────────────────────────────────────────── */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    width: min(420px, 100%);
    background: var(--bg-container);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.45);
    padding: 36px 32px;
    transition: background 0.3s, border-color 0.3s;
}

.login-container h1 {
    font-size: 1.8rem;
    text-align: center;
}

.login-container p.subtitle {
    text-align: center;
    margin: 0 0 28px;
    font-size: 0.95rem;
}

.login-container .field {
    margin-bottom: 20px;
}

.login-container .field label {
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.login-container input {
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 1rem;
}

.login-container button {
    width: 100%;
    border: none;
    border-radius: 14px;
    padding: 15px 22px;
    background: var(--purple);
    color: #f8fafc;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
    margin-top: 8px;
}

.login-container button:hover {
    background: var(--purple-hover);
    transform: translateY(-1px);
}

.login-container .error {
    background: var(--red-soft);
    border: 1px solid var(--red-soft-border);
    border-radius: 12px;
    padding: 12px 16px;
    color: var(--red-text);
    font-size: 0.9rem;
    margin-bottom: 20px;
    text-align: center;
}

[data-theme="light"] .login-container .error {
    color: var(--light-red-text);
}

.theme-toggle-wrap {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
}

.theme-toggle-wrap .theme-toggle {
    width: 42px;
    height: 42px;
    font-size: 1.3rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 640px) {
    body {
        padding: 16px;
    }

    .container {
        padding: 20px;
    }

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