/* ===== CSS Variables & Themes ===== */
:root {
    --bg: #f5f5f5;
    --surface: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #666;
    --accent: #f97316;
    --accent-hover: #ea580c;
    --border: #e5e7eb;
    --danger: #ef4444;
    --success: #22c55e;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --radius: 12px;
    --sidebar-w: 300px;
}

[data-theme="dark"] {
    --bg: #0f0f1a;
    --surface: #1a1a2e;
    --text: #e0e0e0;
    --text-secondary: #999;
    --accent: #f97316;
    --accent-hover: #fb923c;
    --border: #2a2a4a;
    --shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

/* ===== Screens ===== */
.screen { display: none; }
.screen.active { display: block; }

/* ===== Login Screen ===== */
.login-container {
    max-width: 400px;
    margin: 10vh auto;
    padding: 32px 24px;
    text-align: center;
}
.login-container h1 { font-size: 2rem; margin-bottom: 4px; }
.subtitle { color: var(--text-secondary); margin-bottom: 24px; }

.login-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
}
.tab.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.tab-content { display: none; padding: 20px 0; }
.tab-content.active { display: block; }

.hint { margin-top: 12px; font-size: 13px; color: var(--text-secondary); }
.hint a { color: var(--accent); text-decoration: none; }

/* ===== Forms ===== */
input[type="text"], input[type="password"], input[type="number"] {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 16px;
    margin-bottom: 12px;
    outline: none;
    transition: border-color 0.2s;
}
input:focus { border-color: var(--accent); }

.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary.full { width: 100%; }

.btn-icon {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
}
.btn-icon:hover { background: var(--border); }

.btn-danger {
    background: var(--danger);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}

.btn-small {
    padding: 6px 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
}

/* ===== Navbar ===== */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.navbar h2 { font-size: 1.2rem; }
.nav-actions { display: flex; gap: 8px; }

/* ===== App Layout ===== */
.app-layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px;
    overflow-y: auto;
}
.main-area { flex: 1; padding: 24px; overflow-y: auto; }

/* ===== Lists ===== */
.list { margin-top: 16px; }
.list-item {
    padding: 14px 16px;
    background: var(--bg);
    border-radius: var(--radius);
    margin-bottom: 8px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    border: 2px solid transparent;
}
.list-item:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.list-item.active { border-color: var(--accent); }
.list-item .name { font-weight: 600; margin-bottom: 4px; }
.list-item .meta { font-size: 12px; color: var(--text-secondary); }

.empty { color: var(--text-secondary); font-style: italic; text-align: center; padding: 40px 0; }

/* ===== Calculator ===== */
.estimate-header { margin-bottom: 24px; }
.estimate-header h3 { font-size: 1.4rem; }

.estimate-lines { margin-top: 16px; }
.line-row {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface);
    border-radius: var(--radius);
    margin-bottom: 8px;
    box-shadow: var(--shadow);
    flex-wrap: wrap;
}
.line-row .line-name { flex: 1; min-width: 150px; font-weight: 500; }
.line-row input { width: 100px; margin-bottom: 0; padding: 8px 10px; font-size: 14px; }
.line-row .line-total { font-weight: 700; min-width: 100px; text-align: right; }

.add-line-form {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
}
.add-line-form select {
    padding: 10px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
}

.total-bar {
    margin-top: 24px;
    padding: 16px 20px;
    background: var(--accent);
    color: white;
    border-radius: var(--radius);
    font-size: 1.3rem;
    font-weight: 700;
    text-align: right;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: var(--radius);
    color: white;
    font-weight: 600;
    z-index: 100;
    animation: slideUp 0.3s ease;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes slideUp { from { opacity: 0; transform: translateX(-50%) translateY(20px); } }

/* ===== Print (PDF export) ===== */
@media print {
    .navbar, .sidebar, .btn-icon, .btn-primary, .btn-danger, .btn-small, .add-line-form, .toast { display: none !important; }
    .app-layout { display: block; }
    .main-area { padding: 0; }
    body { background: white; color: black; }
}

/* ===== Mobile (≤768px) ===== */
@media (max-width: 768px) {
    .app-layout { flex-direction: column; }
    .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); padding: 12px; }
    .main-area { padding: 16px; }
    .navbar h2 { font-size: 1rem; }
    .line-row { flex-direction: column; align-items: flex-start; }
    .line-row .line-total { text-align: left; }
    .add-line-form { flex-direction: column; }
    .add-line-form select { width: 100%; }
    .login-container { margin: 5vh auto; padding: 20px 16px; }
}

/* ===== Desktop (≥769px) ===== */
@media (min-width: 769px) {
    .estimate-lines { display: table; width: 100%; }
    .line-row { display: table-row; }
    .line-row > * { display: table-cell; vertical-align: middle; padding: 10px 12px; }
}
