:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --text: #1f2933;
    --muted: #6b7280;
    --primary: #0b5ea8;
    --accent: #e6f0fa;
    --border: #e5e7eb;
    --danger: #a61b1b;
}
[data-theme="dark"] {
    --bg: #0f172a;
    --card: #111827;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --primary: #60a5fa;
    --accent: #0b1220;
    --border: #1f2937;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}
img { max-width: 100%; height: auto; }
.hidden { display: none !important; }

.app {
    max-width: 520px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
}
.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand img {
    width: 32px;
    height: 32px;
}
.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}
.brand-title {
    font-weight: 700;
    font-size: 0.9rem;
}
.brand-slogan {
    font-size: 0.7rem;
    color: var(--muted);
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.toggle-btn, .logout-btn {
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    cursor: pointer;
}
.logout-btn {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.screen { display: none; }
.screen.active { display: block; }
.auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.shell {
    width: 100%;
    max-width: 420px;
}
.shell .brand {
    flex-direction: column;
    text-align: center;
    gap: 8px;
    margin-bottom: 16px;
}
.shell .brand img {
    width: 64px;
    height: 64px;
}
.title {
    font-size: 1.1rem;
    margin-bottom: 6px;
    text-align: center;
}
.subtitle {
    font-size: 0.9rem;
    color: var(--muted);
    line-height: 1.4;
    text-align: center;
    margin-bottom: 14px;
}
label {
    font-size: 0.85rem;
    font-weight: 600;
    display: block;
    margin-bottom: 6px;
}
input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.95rem;
    margin-bottom: 10px;
    background: var(--card);
    color: var(--text);
}
.pin-input {
    font-size: 1.2rem;
    text-align: center;
    letter-spacing: 0.4em;
}
.btn {
    width: 100%;
    border: 1px solid #111827;
    background: #111827;
    color: #ffffff;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
}
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.install-btn {
    width: 100%;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #ffffff;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    margin-top: 12px;
}
.helper {
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--muted);
    text-align: center;
    min-height: 1em;
}
.login-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.82rem;
    min-height: 1.2em;
}
.login-status .spinner {
    width: 18px;
    height: 18px;
    border-width: 2px;
    border-top-color: var(--primary);
    margin: 0;
}
.error {
    background: #fff3f3;
    border: 1px solid #f5c2c7;
    color: var(--danger);
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 10px;
    text-align: center;
}
.waiting-shell {
    text-align: center;
}
.waiting-shell .brand-title {
    font-weight: 700;
    font-size: 1rem;
    margin-top: 6px;
}
.waiting-shell .brand-slogan {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 16px;
}
.spinner {
    width: 34px;
    height: 34px;
    border: 3px solid var(--border);
    border-top-color: #111827;
    border-radius: 50%;
    margin: 0 auto 12px;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.dashboard-screen .content {
    flex: 1;
    padding: 16px 14px 80px;
}
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
}
.card h2 {
    font-size: 1rem;
    margin-bottom: 6px;
}
.card p {
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.4;
}
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 12px;
}
.analytics-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
}
.analytics-item strong {
    display: block;
    font-size: 1rem;
    margin-bottom: 2px;
}
.analytics-item span {
    color: var(--muted);
    font-size: 0.8rem;
}
.month-stats {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.85rem;
}
.month-chip {
    background: var(--accent);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 8px;
    color: var(--text);
}
.ref-link-box {
    margin-top: 10px;
    background: var(--accent);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ref-link-box input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 0.85rem;
}
.ref-copy-btn {
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #ffffff;
    padding: 6px 8px;
    border-radius: 8px;
    font-size: 0.8rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.ref-copy-btn svg { width: 16px; height: 16px; }
.weekly-logs {
    margin-top: 14px;
}
.weekly-logs h3 {
    font-size: 0.95rem;
    margin-bottom: 6px;
}
.weekly-summary {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 8px;
}
.weekly-summary strong { color: var(--text); }

.job-item {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 10px;
}
.job-title, .job-meta {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.job-title {
    font-weight: 700;
    margin-bottom: 4px;
}
.job-meta {
    color: var(--muted);
    font-size: 0.85rem;
    margin-bottom: 6px;
}
.job-salary { font-size: 0.85rem; }
.share-btn {
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #ffffff;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
}
.share-icon { width: 16px; height: 16px; display: block; }

.ref-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.ref-table th, .ref-table td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    margin-right: 6px;
    vertical-align: middle;
}
.status-dot.pending { background: #9ca3af; }
.status-dot.qualified { background: #22c55e; }
.status-dot.rejected { background: #ef4444; }
.ref-row.pending { background: #f3f4f6; }
.ref-row.paid { background: #e8f5e9; }
.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.search-box { margin-top: 10px; }
.search-box input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
}

.ref-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 16px;
}
.ref-modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    max-width: 360px;
    width: 100%;
    text-align: left;
}
.ref-modal h4 { margin-bottom: 8px; font-size: 1rem; }
.ref-modal p { margin: 6px 0; color: var(--muted); font-size: 0.9rem; }
.ref-modal .status { font-weight: 600; color: var(--text); }
.ref-modal-close {
    margin-top: 10px;
    width: 100%;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    width: 100%;
}
.tab-btn {
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    padding: 10px 6px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}
.tab-btn.active {
    background: var(--accent);
    border-color: var(--primary);
    color: var(--primary);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: #111827;
    color: #fff;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 3000;
}
.toast.show { opacity: 1; }

@media (min-width: 768px) {
    .app { max-width: 680px; }
}
@media (max-width: 520px) {
    .dashboard-screen .content {
        padding: 12px 10px 80px;
    }
    .card { padding: 12px; }
    .analytics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ref-link-box { flex-direction: column; align-items: stretch; }
    .ref-copy-btn { justify-content: center; }
    .month-stats { gap: 6px; }
    .month-chip { font-size: 0.78rem; }
    .ref-table th,
    .ref-table td {
        font-size: 0.78rem;
        padding: 4px 6px;
        white-space: nowrap;
    }
    .install-btn {
        font-size: 0.9rem;
    }
}
