/* ============================================================
   ORDER TRACKING SYSTEM — COMPLETE STYLESHEET
   Mobile-first, responsive, modern, clean design.
   ============================================================ */

/* ── CSS Variables ── */
:root {
    --primary: #2563EB;
    --primary-dark: #1D4ED8;
    --primary-light: #DBEAFE;
    --success: #16A34A;
    --success-light: #DCFCE7;
    --warning: #D97706;
    --warning-light: #FEF3C7;
    --danger: #DC2626;
    --danger-light: #FEE2E2;
    --info: #0891B2;
    --info-light: #CFFAFE;

    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --gray-500: #6B7280;
    --gray-600: #4B5563;
    --gray-700: #374151;
    --gray-800: #1F2937;
    --gray-900: #111827;

    --bg: #F3F4F6;
    --card-bg: #FFFFFF;
    --text: #1F2937;
    --text-muted: #6B7280;
    --border: #E5E7EB;

    --sidebar-w: 260px;
    --sidebar-bg: #1E293B;
    --sidebar-text: #CBD5E1;
    --sidebar-active: #2563EB;

    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --transition: 0.2s ease;

    /* Status colors */
    --status-primljeno: #3B82F6;
    --status-pripremljeno: #F59E0B;
    --status-zavrseno: #10B981;
    --status-javljeno: #8B5CF6;
    --status-isporuceno: #6B7280;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
table { border-collapse: collapse; width: 100%; }

/* ── Auth Pages (login/register) ── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, #1E293B 0%, #334155 100%);
}
.auth-container { width: 100%; max-width: 420px; }
.auth-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    box-shadow: var(--shadow-md);
}
.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}
.logo-icon-lg {
    font-size: 48px;
    display: block;
    margin-bottom: 8px;
}
.auth-logo h1 {
    font-size: 24px;
    color: var(--gray-900);
    margin-bottom: 4px;
}
.auth-logo p {
    color: var(--text-muted);
    font-size: 14px;
}
.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
}

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    z-index: 1000;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform var(--transition);
    padding-top: env(safe-area-inset-top, 0px);
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}
.sidebar-overlay.active { display: block; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 8px;
}
.logo-icon {
    font-size: 20px;
    color: var(--primary);
}
.logo-text {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
}
.sidebar-close {
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
}
.sidebar-nav { padding: 12px 0; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--sidebar-text);
    font-size: 14px;
    transition: background var(--transition), color var(--transition);
    text-decoration: none;
}
.nav-link:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
    text-decoration: none;
}
.nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-divider {
    margin: 8px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.nav-section-title {
    padding: 8px 20px 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--gray-400);
}
.nav-logout { color: #F87171; }
.nav-logout:hover { background: rgba(248,113,113,0.15); color: #FCA5A5; }
.nav-user-info {
    padding: 16px 20px;
    font-size: 12px;
    color: var(--gray-400);
    border-top: 1px solid rgba(255,255,255,0.08);
    margin-top: 8px;
}

/* Status dots in nav */
.status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.dot-primljeno    { background: var(--status-primljeno); }
.dot-pripremljeno { background: var(--status-pripremljeno); }
.dot-zavrseno     { background: var(--status-zavrseno); }
.dot-javljeno     { background: var(--status-javljeno); }
.dot-isporuceno   { background: var(--status-isporuceno); }

/* ── Top Bar (mobile) ── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    padding: 12px 16px;
    padding-top: max(env(safe-area-inset-top, 0px), 12px);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 0;
}
.hamburger {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 4px;
}
.hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--gray-700);
    border-radius: 2px;
}
.topbar-title {
    flex: 1;
    text-align: center;
    font-weight: 600;
    font-size: 16px;
    color: var(--gray-800);
}
.topbar-spacer { width: 30px; }

/* ── Main Content ── */
.main-content {
    padding: 16px;
    max-width: 1400px;
    margin: 0 auto;
}

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: 8px;
}
.page-header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ── Cards ── */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.card h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 16px;
}

/* ── Section Header ── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}
.section-header h2 { margin-bottom: 0; }

/* ── Statistics Grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--gray-300);
}
.stat-number {
    font-size: 28px;
    font-weight: 700;
    color: var(--gray-900);
}
.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}
.stat-total    { border-left-color: var(--primary); }
.stat-active   { border-left-color: var(--success); }
.stat-primljeno    { border-left-color: var(--status-primljeno); }
.stat-pripremljeno { border-left-color: var(--status-pripremljeno); }
.stat-zavrseno     { border-left-color: var(--status-zavrseno); }
.stat-javljeno     { border-left-color: var(--status-javljeno); }
.stat-isporuceno   { border-left-color: var(--status-isporuceno); }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    min-height: 44px; /* Apple HIG minimum touch target */
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--primary-dark);
}
.btn-outline {
    background: transparent;
    color: var(--gray-700);
    border: 1px solid var(--border);
}
.btn-outline:hover {
    background: var(--gray-100);
}
.btn-block { width: 100%; }
.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}
.btn-lg {
    padding: 14px 28px;
    font-size: 16px;
}

/* ── Alerts ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}
.alert-error {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #FECACA;
}
.alert-success {
    background: var(--success-light);
    color: var(--success);
    border: 1px solid #BBF7D0;
}
.alert a { color: inherit; font-weight: 600; text-decoration: underline; }

/* ── Forms ── */
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 4px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: 16px; /* ≥16px prevents iOS auto-zoom on focus */
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
    color: var(--text);
    transition: border-color var(--transition);
    -webkit-appearance: none; /* consistent look on iOS */
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group textarea { resize: vertical; }
.form-row {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.full-width { grid-column: 1 / -1; }
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}
.form-group-btn {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.input-sm {
    padding: 6px 10px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 160px;
}
.inline-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.flex-2 { flex: 2; }

/* ── Data Tables ── */
.table-responsive { overflow-x: auto; }
.data-table {
    width: 100%;
    font-size: 13px;
}
.data-table thead th {
    background: var(--gray-50);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--gray-600);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.data-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--gray-50); }
.clickable-row { cursor: pointer; }

/* ── Status Badges ── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 20px;
    white-space: nowrap;
}
.badge-primljeno    { background: #DBEAFE; color: #1D4ED8; }
.badge-pripremljeno { background: #FEF3C7; color: #92400E; }
.badge-zavrseno     { background: #D1FAE5; color: #065F46; }
.badge-javljeno     { background: #EDE9FE; color: #5B21B6; }
.badge-isporuceno   { background: #F3F4F6; color: #374151; }
.badge-admin        { background: #DBEAFE; color: #1D4ED8; }
.badge-employee     { background: #F3F4F6; color: #374151; }

/* ── Status Update Highlight Animation ── */
@keyframes statusHighlight {
    0%   { background-color: #bbf7d0; }
    100% { background-color: transparent; }
}
.status-updated-highlight {
    animation: statusHighlight 1.8s ease-out;
}
tr.status-updated-highlight > td {
    animation: statusHighlight 1.8s ease-out;
}

/* ── Inline Status Select ── */
.status-select {
    padding: 6px 10px;
    font-size: 16px; /* prevents iOS zoom */
    min-height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
    cursor: pointer;
}
.status-select:focus {
    outline: none;
    border-color: var(--primary);
}

/* ── Quick Navigation ── */
.quick-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}
.quick-nav-btn {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--gray-700);
    text-decoration: none;
    transition: all var(--transition);
    box-shadow: var(--shadow);
}
.quick-nav-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    text-decoration: none;
}
.qn-primljeno    { border-left: 3px solid var(--status-primljeno); }
.qn-pripremljeno { border-left: 3px solid var(--status-pripremljeno); }
.qn-zavrseno     { border-left: 3px solid var(--status-zavrseno); }
.qn-javljeno     { border-left: 3px solid var(--status-javljeno); }
.qn-isporuceno   { border-left: 3px solid var(--status-isporuceno); }

/* ── Mobile Order Cards ── */
.order-card {
    display: block;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    text-decoration: none;
    color: var(--text);
    transition: box-shadow var(--transition);
}
.order-card:hover {
    box-shadow: var(--shadow-md);
    text-decoration: none;
}
.order-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.order-card-id {
    font-weight: 700;
    color: var(--gray-500);
    font-size: 13px;
}
.order-card-body { margin-bottom: 8px; }
.order-card-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--gray-900);
}
.order-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-muted);
}
.order-card-meta span { display: inline-flex; align-items: center; gap: 2px; }
.order-card-model {
    font-size: 13px;
    color: var(--gray-600);
    margin-top: 4px;
}
.order-card-footer {
    padding-top: 8px;
    border-top: 1px solid var(--gray-100);
}

/* ── Order Detail Grid ── */
.order-detail-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
.detail-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.detail-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}
.detail-value {
    font-size: 15px;
    color: var(--gray-900);
    word-break: break-word;
}
.detail-value a { color: var(--primary); }

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}
.tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition);
}
.tab:hover { color: var(--primary); text-decoration: none; }
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ── Chart Card ── */
.chart-card {
    overflow: hidden;
    padding: 16px;
}
.chart-card canvas {
    width: 100% !important;
    max-height: 300px;
    display: block;
}

/* ── History Table ── */
.history-table { font-size: 12px; }
.history-table td, .history-table th { padding: 8px 10px; }

/* ── Empty State ── */
.empty-text {
    text-align: center;
    color: var(--text-muted);
    padding: 24px;
    font-size: 14px;
}

/* ── Print area (hidden outside print) ── */
.print-area { display: none; }

/* ── Responsive visibility ── */
.desktop-only { display: none; }
.mobile-only  { display: block; }

/* ============================================================
   TABLET (≥ 768px)
   ============================================================ */
@media (min-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .form-row {
        flex-direction: row;
        gap: 16px;
    }
    .form-row .form-group { flex: 1; }
    .order-detail-grid {
        grid-template-columns: 1fr 1fr;
    }
    .main-content {
        padding: 24px;
    }
}

/* ============================================================
   DESKTOP (≥ 1024px)
   ============================================================ */
@media (min-width: 1024px) {
    /* Show sidebar permanently */
    .sidebar {
        transform: translateX(0);
    }
    .sidebar-close { display: none; }
    .sidebar-overlay { display: none !important; }
    .topbar { display: none; }

    .main-content {
        margin-left: var(--sidebar-w);
        padding: 32px 40px;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .desktop-only { display: block; }
    .mobile-only  { display: none; }

    .form-row {
        flex-direction: row;
        gap: 16px;
    }
    .form-row .form-group { flex: 1; }

    .order-detail-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .page-header h1 { font-size: 26px; }
}

/* ============================================================
   LARGE DESKTOP (≥ 1400px)
   ============================================================ */
@media (min-width: 1400px) {
    .stats-grid {
        grid-template-columns: repeat(7, 1fr);
    }
}

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
    body {
        background: #fff;
        font-family: 'Segoe UI', Arial, sans-serif;
        font-size: 13px;
        color: #222;
    }
    .sidebar, .topbar, .no-print,
    .page-header-actions, .status-select,
    .inline-status, .inline-status-single,
    #orderEdit, #orderHistory,
    .page-header, .alert { display: none !important; }

    .main-content {
        margin: 0;
        padding: 0;
    }
    .card {
        box-shadow: none;
        border: none;
        padding: 0;
    }
    #orderView { display: none !important; }
    #printArea {
        display: block !important;
        padding: 0;
    }
    .print-header {
        text-align: center;
        margin-bottom: 28px;
        border-bottom: 2px solid #333;
        padding-bottom: 18px;
    }
    .print-logo-img {
        display: block;
        max-width: 200px;
        height: auto;
        margin: 0 auto 16px auto;
    }
    .print-header h1 {
        font-size: 22px;
        margin: 0;
        letter-spacing: 0.5px;
    }
    .print-table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 12px;
    }
    .print-table th,
    .print-table td {
        padding: 10px 14px;
        border: 1px solid #ccc;
        text-align: left;
        font-size: 13px;
        line-height: 1.5;
    }
    .print-table th {
        background: #f0f0f0;
        font-weight: 600;
        width: 180px;
        color: #333;
    }
    .print-table td {
        color: #222;
    }
    .print-table tr:nth-child(even) td {
        background: #fafafa;
    }

    @page {
        size: A4;
        margin: 15mm;
    }
}

/* ── Search form tweaks ── */
.search-form .form-row {
    align-items: normal !important;
}
