/* ======================================================
   QUATECH SERVİS – Design System
   Premium, Dark Theme, Mobile-First
   ====================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ──── CSS Custom Properties ──── */
:root {
    /* Light Mode Default Colors */
    --color-bg: #f8fafc;
    --color-bg-elevated: #ffffff;
    --color-bg-card: #f1f5f9;
    --color-bg-input: #e2e8f0;
    --color-bg-hover: #cbd5e1;

    --color-primary: #3b82f6;
    --color-primary-hover: #2563eb;
    --color-primary-light: rgba(59, 130, 246, 0.12);

    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-info: #06b6d4;

    --color-text: #0f172a;
    --color-text-secondary: #475569;
    --color-text-muted: #64748b;

    --color-border: #cbd5e1;
    --color-border-focus: var(--color-primary);
}

/* Dark Theme overrides */
@media (prefers-color-scheme: dark) {
    :root:not(.light-theme) {
        --color-bg: #0f1117;
        --color-bg-elevated: #1a1d27;
        --color-bg-card: #21242f;
        --color-bg-input: #282c3a;
        --color-bg-hover: #2d3142;

        --color-text: #e8eaed;
        --color-text-secondary: #9ca3af;
        --color-text-muted: #6b7280;

        --color-border: #2d3142;
    }
}

:root.dark-theme {
    --color-bg: #0f1117;
    --color-bg-elevated: #1a1d27;
    --color-bg-card: #21242f;
    --color-bg-input: #282c3a;
    --color-bg-hover: #2d3142;

    --color-text: #e8eaed;
    --color-text-secondary: #9ca3af;
    --color-text-muted: #6b7280;

    --color-border: #2d3142;
}

/* Explicit light-theme always stays light regardless of system preference */
:root.light-theme {
    --color-bg: #f8fafc;
    --color-bg-elevated: #ffffff;
    --color-bg-card: #f1f5f9;
    --color-bg-input: #e2e8f0;
    --color-bg-hover: #cbd5e1;

    --color-text: #0f172a;
    --color-text-secondary: #475569;
    --color-text-muted: #64748b;

    --color-border: #cbd5e1;
}

:root {

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    /* Border radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ──── Form Elements ──── */
.form-group {
    margin-bottom: var(--space-5);
}

.form-group label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-2);
    letter-spacing: 0.01em;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-input);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
    /* Tablet-friendly: büyük dokunmatik alanlar */
    min-height: 48px;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-input::placeholder {
    color: var(--color-text-muted);
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

/* ──── Buttons ──── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-6);
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: 48px;
    text-decoration: none;
    user-select: none;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    background: var(--color-bg-hover);
    color: var(--color-text);
    border: 1.5px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-bg-input);
    border-color: var(--color-text-muted);
}

.btn-success {
    background: var(--color-success);
    color: white;
}

.btn-danger {
    background: var(--color-danger);
    color: white;
}

.btn-full {
    width: 100%;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-lg {
    min-height: 56px;
    font-size: var(--font-size-lg);
    padding: var(--space-4) var(--space-8);
    border-radius: var(--radius-lg);
}

/* ──── Cards ──── */
.card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

/* ──── Alerts ──── */
.alert {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-5);
}

.alert-error {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.alert-success {
    background: rgba(34, 197, 94, 0.12);
    color: #86efac;
    border: 1px solid rgba(34, 197, 94, 0.25);
}

.alert-warning {
    background: rgba(245, 158, 11, 0.12);
    color: #fcd34d;
    border: 1px solid rgba(245, 158, 11, 0.25);
}

.alert-icon {
    font-size: var(--font-size-lg);
    flex-shrink: 0;
}

/* ──── Spinner ──── */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ──── Checkbox ──── */
.checkbox-group {
    display: flex;
    align-items: center;
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary) !important;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--color-primary);
}

/* ──── Login Page ──── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: var(--space-4);
    background: radial-gradient(ellipse at top, #1a1d2e 0%, var(--color-bg) 70%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: var(--space-10);
    box-shadow: var(--shadow-lg);
}

.login-brand {
    text-align: center;
    margin-bottom: var(--space-8);
}

.brand-title {
    font-size: var(--font-size-3xl);
    font-weight: 700;
    letter-spacing: 0.08em;
    background: linear-gradient(135deg, var(--color-primary), #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.brand-subtitle {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    margin-top: var(--space-1);
}

/* ──── Layout ──── */
.app-layout {
    display: flex;
    min-height: 100dvh;
}

.app-sidebar {
    width: 260px;
    background: var(--color-bg-elevated);
    border-right: 1px solid var(--color-border);
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    transition: transform var(--transition-normal);
}

.app-main {
    flex: 1;
    margin-left: 260px;
    padding: var(--space-6);
}

.sidebar-brand {
    padding-bottom: var(--space-6);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-4);
}

.sidebar-brand h2 {
    font-size: var(--font-size-lg);
    letter-spacing: 0.04em;
    color: var(--color-primary);
}

.sidebar-nav {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    flex: 1;
}

.sidebar-nav a,
.sidebar-nav button {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: var(--font-size-sm);
    font-weight: 500;
    transition: all var(--transition-fast);
    border: none;
    background: none;
    cursor: pointer;
    width: 100%;
    text-align: left;
    font-family: var(--font-family);
}

.sidebar-nav a:hover,
.sidebar-nav button:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}

.sidebar-nav a.active {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.sidebar-user {
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.sidebar-user strong {
    display: block;
    color: var(--color-text);
    margin-bottom: var(--space-1);
}

/* ──── Page Header ──── */
.page-header {
    margin-bottom: var(--space-6);
}

.page-header h1 {
    font-size: var(--font-size-2xl);
    font-weight: 700;
}

.page-header p {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    margin-top: var(--space-1);
}

/* ──── Hamburger & Mobile Sidebar ──── */
.hamburger-btn {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1000;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.sidebar-close {
    display: none;
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1040;
}

/* ──── Responsive ──── */
@media (max-width: 768px) {
    .hamburger-btn {
        display: block;
    }

    .app-sidebar {
        transform: translateX(-100%);
        z-index: 1050;
    }

    .app-sidebar.sidebar-open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: block;
    }

    .sidebar-backdrop {
        display: none; /* Controlled by JS toggleSidebar() */
    }

    .app-main {
        margin-left: 0;
        padding: var(--space-4);
        padding-top: 4rem; /* For hamburger and spacing */
    }

    .login-card {
        padding: var(--space-6);
    }
}

/* ──── Blazor defaults override ──── */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    width: 100%;
    z-index: 1000;
    padding: var(--space-3) var(--space-4);
    background: var(--color-danger);
    color: white;
    text-align: center;
}

/* ══════════════════════════════════════════════
   WIZARD
   ══════════════════════════════════════════════ */
.wizard-container {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - 3rem);
}

.wizard-header {
    position: sticky;
    top: 0;
    background: var(--color-bg);
    z-index: 10;
    padding: var(--space-4) 0;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-6);
}

.wizard-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-3);
}

.wizard-form-no {
    font-weight: 700;
    font-size: var(--font-size-lg);
    color: var(--color-primary);
}

.wizard-save-status {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}
.wizard-save-status.saved { color: var(--color-success); }
.wizard-save-status.offline { color: var(--color-warning); }

.wizard-steps-indicator {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: var(--space-3);
    flex-wrap: wrap;
}

.step-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--color-border);
    background: var(--color-bg-card);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-family);
}
.step-dot.active {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: white;
}
.step-dot.done {
    border-color: var(--color-success);
    color: var(--color-success);
}

.wizard-step-title {
    text-align: center;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-secondary);
}

.wizard-body {
    flex: 1;
    padding-bottom: 100px;
}

.wizard-body h2 {
    font-size: var(--font-size-xl);
    font-weight: 700;
    margin-bottom: var(--space-4);
}

.wizard-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: var(--space-4);
    padding: var(--space-4);
    background: var(--color-bg-elevated);
    border-top: 1px solid var(--color-border);
    z-index: 20;
    max-width: 720px;
    margin: 0 auto;
}

.wizard-footer .btn {
    flex: 1;
}

/* ── Toggle Buttons ── */
.toggle-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.toggle-btn {
    flex: 1;
    min-width: 120px;
    min-height: 56px;
    padding: var(--space-3) var(--space-4);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-bg-card);
    color: var(--color-text-secondary);
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.toggle-btn:hover {
    border-color: var(--color-text-muted);
}

.toggle-btn.active {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
    color: var(--color-primary);
}

/* ── Checks ── */
.checks-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.check-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--color-bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.check-label {
    flex: 1;
    font-size: var(--font-size-sm);
    line-height: 1.4;
}

.check-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--color-bg-hover);
    font-size: var(--font-size-xs);
    font-weight: 700;
    margin-right: var(--space-2);
    flex-shrink: 0;
}

.check-buttons {
    display: flex;
    gap: var(--space-2);
    flex-shrink: 0;
}

.check-btn {
    min-width: 60px;
    min-height: 40px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-input);
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-family);
}

.check-btn.yes-active {
    border-color: var(--color-success);
    background: rgba(34, 197, 94, 0.15);
    color: var(--color-success);
}

.check-btn.no-active {
    border-color: var(--color-danger);
    background: rgba(239, 68, 68, 0.15);
    color: var(--color-danger);
}

/* ── Unit Cards ── */
.unit-cards {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.unit-card .form-group {
    margin-bottom: var(--space-3);
}

.unit-card-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-3);
}

/* ── Measurement Table ── */
.measurement-table {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.mt-header {
    display: grid;
    grid-template-columns: 1fr 70px 70px 70px;
    gap: var(--space-2);
    font-size: var(--font-size-xs);
    font-weight: 700;
    color: var(--color-text-muted);
    text-align: center;
    padding: 0 var(--space-2);
}

.mt-row {
    display: grid;
    grid-template-columns: 1fr 70px 70px 70px;
    gap: var(--space-2);
    align-items: center;
}

.mt-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    padding: 0 var(--space-2);
}

.mt-input {
    min-height: 38px !important;
    padding: var(--space-2) !important;
    font-size: var(--font-size-sm) !important;
    text-align: center;
}

/* ── Admin Table ── */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th, .data-table td {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
}

.data-table th {
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table tr:hover td {
    background: var(--color-bg-hover);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: 600;
}

.status-badge.draft { background: rgba(107,114,128,0.2); color: #9ca3af; }
.status-badge.approved { background: rgba(34,197,94,0.15); color: #86efac; }
.status-badge.otp-sent, .status-badge.link-sent { background: rgba(59,130,246,0.15); color: #93c5fd; }
.status-badge.rejected { background: rgba(239,68,68,0.15); color: #fca5a5; }
.status-badge.expired { background: rgba(245,158,11,0.15); color: #fcd34d; }

/* ── Filters ── */
.filters-bar {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-6);
}

.filters-bar .form-input,
.filters-bar .form-select {
    min-width: 160px;
    flex: 1;
    min-height: 42px;
}

@media (max-width: 768px) {
    .wizard-footer {
        max-width: 100%;
    }
    .mt-header, .mt-row {
        grid-template-columns: 1fr 60px 60px 60px;
    }
    .mt-input {
        padding: var(--space-1) !important;
    }
}

/* ══════════════════════════════════════════════
   DASHBOARD
   ══════════════════════════════════════════════ */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
}

.stat-card {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
}

.quick-action-card {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    text-decoration: none;
    color: inherit;
    transition: all var(--transition-fast);
}

.quick-action-card:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
    transform: translateY(-2px);
}

.quick-action-card h3 {
    font-size: var(--font-size-md);
    margin-bottom: var(--space-1);
}

.quick-action-card p {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.qa-icon {
    font-size: 1.75rem;
    flex-shrink: 0;
}

/* ── Detail Grid ── */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 0;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
}

.detail-label {
    color: var(--color-text-muted);
    font-weight: 500;
}

.detail-value {
    font-weight: 600;
    text-align: right;
}