/* Better Safe App — Responsive Design */

:root {
    --primary: #4a2d7a;
    --primary-light: #6b4d9a;
    --accent: #5a3a8a;
    --accent-bright: #7ab51d;
    --bg: #f7f7f9;
    --card: #ffffff;
    --text: #2c2c3a;
    --text-light: #6e6e80;
    --border: #e0e0e0;
    --success: #7ab51d;
    --warning: #f39c12;
    --danger: #e74c3c;
    --info: #4a2d7a;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(74,45,122,0.10);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Screens --- */
.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }

/* --- Header --- */
header {
    background: var(--primary);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
header h2 { font-size: 18px; font-weight: 600; }
.header-left { display: flex; flex-direction: column; }
.header-right { display: flex; gap: 4px; }
.date { font-size: 13px; opacity: 0.7; }

.btn-icon {
    background: none; border: none; color: white;
    font-size: 20px; cursor: pointer; padding: 8px;
    min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
}

/* --- Login --- */
.login-container {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; min-height: 100vh; padding: 40px 20px;
    background: linear-gradient(135deg, var(--primary) 0%, #3a1d6a 100%);
}
.logo { text-align: center; margin-bottom: 48px; }
.logo-img { height: 60px; margin-bottom: 16px; }
.logo h1 { color: white; font-size: 32px; letter-spacing: 2px; font-weight: 700; }
.logo h1 .green { color: var(--accent-bright); }
.logo .subtitle { color: rgba(255,255,255,0.6); font-size: 14px; margin-top: 8px; letter-spacing: 2px; }
.login-form { width: 100%; max-width: 320px; }
.login-form label { color: rgba(255,255,255,0.8); font-size: 14px; display: block; margin-bottom: 8px; margin-top: 16px; }
.login-form select {
    width: 100%; padding: 14px; border: 2px solid rgba(255,255,255,0.2);
    border-radius: var(--radius); background: rgba(255,255,255,0.1);
    color: white; font-size: 16px;
    appearance: none; -webkit-appearance: none;
}
.login-form select option { background: var(--primary); color: white; }

/* --- PIN --- */
.pin-group { margin-top: 16px; }

.pin-dots {
    display: flex; justify-content: center; gap: 12px;
    margin: 12px 0;
}
.pin-dots .dot {
    width: 16px; height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.4);
    background: transparent;
    transition: background 0.15s, border-color 0.15s;
}
.pin-dots .dot.filled {
    background: var(--accent-bright);
    border-color: var(--accent-bright);
}

.pin-field {
    width: 100%; padding: 14px;
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: var(--radius);
    background: rgba(255,255,255,0.1);
    color: white; font-size: 24px;
    text-align: center; letter-spacing: 12px;
    -webkit-text-security: disc;
}
.pin-field::placeholder {
    letter-spacing: 2px; font-size: 16px;
    color: rgba(255,255,255,0.4);
}
.pin-field:focus { outline: none; border-color: var(--accent-bright); }

.pin-setup-title {
    color: white; text-align: center;
    font-size: 16px; margin-bottom: 8px;
}

/* --- Buttons --- */
.btn {
    display: block; width: 100%; padding: 14px;
    border: none; border-radius: var(--radius);
    font-size: 16px; font-weight: 600; cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
    margin-top: 16px;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent-bright); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline {
    background: transparent; color: var(--accent);
    border: 2px solid var(--accent);
}
.btn-small { padding: 8px 16px; font-size: 13px; width: auto; display: inline-block; margin-top: 0; }
.btn-lg { padding: 16px; font-size: 18px; margin-top: 20px; }

.btn-icon-inline {
    background: none; border: none;
    font-size: 18px; cursor: pointer;
    padding: 4px 8px; color: var(--info);
    min-width: 44px; min-height: 44px;
    display: inline-flex; align-items: center; justify-content: center;
}

.btn-clear {
    background: none; border: none;
    color: var(--danger); font-size: 20px;
    cursor: pointer; padding: 4px 8px;
    min-width: 44px; min-height: 44px;
}

/* --- Dashboard --- */
.dashboard { padding: 16px; max-width: 600px; margin: 0 auto; }

/* Continue Banner */
.continue-banner {
    background: var(--info); color: white;
    border-radius: var(--radius); padding: 16px;
    margin-bottom: 16px;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
}
.continue-text { display: flex; align-items: center; gap: 12px; flex: 1; }
.continue-text strong { display: block; font-size: 14px; }
.continue-text span:last-child { font-size: 13px; opacity: 0.9; }
.continue-icon { font-size: 24px; }

/* Timer Card */
.timer-card {
    background: var(--primary); color: white;
    border-radius: var(--radius); padding: 24px; margin-bottom: 20px;
    text-align: center;
}
.timer-status { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 8px; }
.pulse {
    width: 10px; height: 10px; background: var(--accent-bright);
    border-radius: 50%; animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.3); }
}
.timer-time { font-size: 48px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 8px 0; }
.timer-customer { font-size: 14px; opacity: 0.8; margin-bottom: 16px; }

.timer-warning {
    background: var(--warning); color: white;
    padding: 10px 16px; border-radius: 8px;
    margin-bottom: 12px; font-size: 13px; font-weight: 600;
}

/* Quick Actions */
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.action-card {
    background: var(--card); border: 2px solid var(--border);
    border-radius: var(--radius); padding: 20px 12px;
    text-align: center; cursor: pointer; transition: border-color 0.2s, transform 0.1s;
}
.action-card:active { transform: scale(0.97); }
.action-card:hover { border-color: var(--accent); }
.action-icon { font-size: 28px; display: block; margin-bottom: 8px; }
.action-label { font-size: 12px; font-weight: 600; color: var(--text-light); }

/* Sections */
.section { margin-bottom: 24px; }
.section h3,
.section-title {
    font-size: 14px; color: var(--text-light);
    text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px;
}

/* Appointment Cards */
.appointment-card {
    background: var(--card); border-radius: var(--radius);
    padding: 14px 16px; margin-bottom: 8px; box-shadow: var(--shadow);
    border-left: 4px solid var(--info);
    cursor: pointer; transition: all 0.2s;
}
.appointment-card.expanded {
    border-left-width: 6px;
}
.appointment-header {
    display: flex; justify-content: space-between; align-items: flex-start;
}
.appointment-main { flex: 1; }
.appointment-time { font-size: 13px; color: var(--info); font-weight: 600; }
.appointment-title { font-size: 15px; font-weight: 600; margin: 4px 0; }
.appointment-address {
    font-size: 13px; color: var(--text-light);
    display: flex; align-items: center; gap: 4px;
}
.appointment-icons {
    display: flex; gap: 4px; flex-shrink: 0;
}
.appointment-auftrag {
    font-size: 13px; color: var(--accent); margin-top: 4px;
    display: flex; align-items: center; gap: 4px;
}
.appointment-details {
    max-height: 0; overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0;
}
.appointment-card.expanded .appointment-details {
    max-height: 200px; padding-top: 12px;
    border-top: 1px solid var(--border); margin-top: 12px;
}
.appointment-actions {
    display: flex; gap: 8px; margin-top: 8px;
}
.appointment-actions .btn { margin-top: 0; }

/* Entry Cards */
.entry-card {
    background: var(--card); border-radius: var(--radius);
    padding: 12px 16px; margin-bottom: 8px; box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 12px;
    border-left: 4px solid var(--success);
    cursor: pointer; transition: background 0.15s;
}
.entry-card:active { background: var(--bg); }
.entry-card.buero { border-left-color: var(--info); }
.entry-card.stoerung { border-left-color: var(--warning); }
.entry-card.nicht-angetroffen { border-left-color: var(--danger); }
.entry-card.deleted { border-left-color: #ccc; opacity: 0.6; text-decoration: line-through; }
.entry-color {
    width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.entry-date { font-size: 13px; color: var(--text-light); min-width: 55px; }
.entry-time { font-size: 13px; color: var(--text-light); min-width: 100px; }
.entry-title { flex: 1; font-weight: 600; font-size: 14px; }
.entry-hours { font-size: 14px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.entry-details { font-size: 12px; color: var(--text-light); }

.empty-state { color: var(--text-light); text-align: center; padding: 24px; font-size: 14px; }
.empty-state.small { padding: 8px; font-size: 13px; }

/* --- Forms --- */
.form-container { padding: 16px; max-width: 600px; margin: 0 auto; }
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: 13px; font-weight: 600;
    color: var(--text-light); margin-bottom: 6px;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.form-row { display: flex; gap: 12px; }
.form-group.half { flex: 1; }

input[type="text"], input[type="tel"], input[type="date"],
input[type="time"], input[type="number"], input[type="month"],
input[type="file"], select, textarea {
    width: 100%; padding: 12px; border: 2px solid var(--border);
    border-radius: var(--radius); font-size: 16px;
    background: var(--card); color: var(--text);
    transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--accent);
}
textarea { resize: vertical; }
input[readonly] { background: var(--bg); color: var(--text-light); }

/* Selected Item (Kunde gewaehlt) */
.selected-item {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--bg); border-radius: var(--radius);
    padding: 10px 12px; margin-top: 8px;
    border: 2px solid var(--accent);
}
.selected-item span { font-weight: 600; }

/* Search Results */
.search-results {
    background: var(--card); border: 2px solid var(--border);
    border-radius: var(--radius); max-height: 200px; overflow-y: auto;
    margin-top: -2px; border-top: none;
    border-top-left-radius: 0; border-top-right-radius: 0;
    position: relative; z-index: 10;
}
.search-result {
    padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 2px;
    min-height: 44px; justify-content: center;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result:active { background: var(--bg); }
.search-result strong { font-size: 15px; }
.search-result span { font-size: 13px; color: var(--text-light); }

/* Fahrzeit Info */
.fahrzeit-info {
    background: #e8f5e9; border-radius: var(--radius);
    padding: 12px 16px; margin-bottom: 16px;
    font-size: 14px; color: #2e7d32;
    border: 1px solid #a5d6a7;
}

/* Summary Card */
.summary-card {
    background: var(--card); border-radius: var(--radius);
    padding: 16px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.summary-highlight {
    border: 2px solid var(--accent);
}
.summary-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 12px; padding-bottom: 8px;
    border-bottom: 2px solid var(--accent);
}
.summary-header strong { font-size: 14px; text-transform: uppercase; letter-spacing: 1px; }
.summary-header span { font-size: 12px; color: var(--text-light); }
.summary-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 0;
}
.summary-row span { color: var(--text-light); font-size: 14px; }
.summary-row strong { font-size: 15px; text-align: right; }
.summary-total {
    border-top: 2px solid var(--text);
    padding-top: 10px; margin-top: 4px;
}
.summary-total strong { font-size: 18px; }
.summary-divider {
    height: 1px; background: var(--border); margin: 8px 0;
}
.text-warning { color: var(--warning) !important; }

.row-with-action {
    display: flex; align-items: center; gap: 4px;
}

.export-btn { margin-top: 16px; width: 100%; text-align: center; }

/* Auftrag Positionen */
.auftrag-lines-container { margin-bottom: 16px; }
.auftrag-line {
    display: grid;
    grid-template-columns: 60px 1fr 40px 80px;
    gap: 8px; align-items: center;
    padding: 10px 12px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.auftrag-line:first-child {
    border-radius: var(--radius) var(--radius) 0 0;
}
.auftrag-line:last-child {
    border-radius: 0 0 var(--radius) var(--radius);
    border-bottom: none;
}
.auftrag-line-header {
    background: var(--primary); color: white;
    font-weight: 600; font-size: 12px;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.auftrag-line .line-ref { font-size: 12px; color: var(--text-light); overflow: hidden; text-overflow: ellipsis; }
.auftrag-line .line-label { font-weight: 500; }
.auftrag-line .line-qty { text-align: center; }
.auftrag-line .line-price { text-align: right; font-weight: 600; }

@media (max-width: 400px) {
    .auftrag-line {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    .auftrag-line .line-ref,
    .auftrag-line .line-qty,
    .auftrag-line .line-price { font-size: 13px; }
    .auftrag-line-header { display: none; }
}

/* Signature Canvas */
.canvas-wrapper { width: 100%; overflow: hidden; }
#ss-signatur {
    width: 100%; max-width: 600px; height: auto;
    border: 2px solid var(--border);
    border-radius: var(--radius); touch-action: none;
    cursor: crosshair;
}
.signature-actions { margin-top: 8px; text-align: right; }

/* Material Liste */
.material-list { margin-bottom: 8px; }
.material-item {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg); border-radius: 8px;
    padding: 8px 12px; margin-bottom: 4px;
}
.material-item .mat-ref { font-size: 12px; color: var(--text-light); min-width: 60px; }
.material-item .mat-name { flex: 1; font-size: 14px; }
.material-item .mat-qty {
    width: 50px; padding: 4px 8px; border: 1px solid var(--border);
    border-radius: 6px; text-align: center; font-size: 14px;
}
.material-item .mat-remove {
    background: none; border: none; color: var(--danger);
    font-size: 18px; cursor: pointer; padding: 4px;
    min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
}
.material-add { position: relative; }

/* Foto Preview */
.foto-preview { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.foto-thumb {
    width: 80px; height: 80px; object-fit: cover;
    border-radius: 8px; border: 2px solid var(--border);
}

/* Options / Checkboxen */
.options-group { margin-top: 20px; }
.checkbox-label {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 12px 0; cursor: pointer;
    border-bottom: 1px solid var(--border);
    min-height: 44px;
}
.checkbox-label input[type="checkbox"] {
    width: 22px; height: 22px; flex-shrink: 0;
    margin-top: 2px; accent-color: var(--accent);
    cursor: pointer;
}
.checkbox-label span { font-size: 15px; line-height: 1.4; }

.conditional-field {
    overflow: hidden; max-height: 0;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0 0 0 34px;
}
.conditional-field.visible {
    max-height: 120px; padding: 8px 0 8px 34px;
}

/* Modifications / History */
.modifications {
    margin: 16px 0; padding: 12px;
    background: var(--bg); border-radius: var(--radius);
}
.modifications h4 {
    font-size: 13px; color: var(--text-light);
    text-transform: uppercase; letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.mod-entry {
    font-size: 13px; color: var(--text-light);
    padding: 4px 0; border-bottom: 1px solid var(--border);
}
.mod-entry:last-child { border-bottom: none; }

/* Action Buttons (Edit Screen) */
.action-buttons {
    display: flex; gap: 12px; margin-top: 20px;
}
.action-buttons .btn { flex: 1; }

/* Settings */
.settings-section {
    background: var(--card); border-radius: var(--radius);
    padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.settings-section h3 {
    font-size: 14px; text-transform: uppercase;
    letter-spacing: 1px; color: var(--text-light);
    margin-bottom: 16px;
}
.info-row {
    display: flex; justify-content: space-between;
    padding: 10px 0; border-bottom: 1px solid var(--border);
}
.info-row:last-child { border-bottom: none; }
.info-row span { color: var(--text-light); font-size: 14px; }
.info-row strong { font-size: 14px; }

/* --- Loading --- */
.loading {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(26,26,46,0.8); display: flex;
    flex-direction: column; align-items: center; justify-content: center; z-index: 1000;
}
.spinner {
    width: 48px; height: 48px; border: 4px solid rgba(255,255,255,0.2);
    border-top-color: var(--accent-bright); border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading p { color: white; margin-top: 16px; }

/* --- Toast --- */
#toast-container { position: fixed; bottom: 20px; left: 20px; right: 20px; z-index: 2000; }
.toast {
    padding: 14px 20px; border-radius: var(--radius); margin-top: 8px;
    font-size: 14px; font-weight: 500; opacity: 0;
    transition: opacity 0.3s, transform 0.3s; transform: translateY(20px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-warning { background: var(--warning); color: white; }
.toast-info { background: var(--info); color: white; }

/* --- Hidden --- */
.hidden { display: none !important; }

/* --- Responsive --- */
@media (max-width: 400px) {
    .quick-actions { grid-template-columns: repeat(2, 1fr); }
    .timer-time { font-size: 36px; }
    header h2 { font-size: 16px; }
    .form-row { flex-direction: column; gap: 0; }
    .form-group.half { flex: none; }
}

/* Safe area for notch devices */
@supports (padding-top: env(safe-area-inset-top)) {
    header {
        padding-top: calc(16px + env(safe-area-inset-top));
    }
    #toast-container {
        bottom: calc(20px + env(safe-area-inset-bottom));
    }
}
