/* =====================================================================
   ERP WMS - Design System
   Nowoczesny, jasny, przejrzysty interfejs inspirowany panelami SaaS.
   ===================================================================== */

:root {
    --color-bg: #f4f6f9;
    --color-surface: #ffffff;
    --color-surface-alt: #f8fafc;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-text-faint: #94a3b8;

    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-primary-light: #eff6ff;

    --color-success: #16a34a;
    --color-success-light: #f0fdf4;
    --color-warning: #d97706;
    --color-warning-light: #fffbeb;
    --color-danger: #dc2626;
    --color-danger-light: #fef2f2;
    --color-info: #0891b2;
    --color-info-light: #ecfeff;

    --sidebar-width: 264px;
    --sidebar-width-collapsed: 76px;
    --topbar-height: 64px;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }

/* ---------------------------------------------------------------------
   Layout
   --------------------------------------------------------------------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: #111827;
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 40;
    transition: width 0.2s ease, transform 0.2s ease;
    overflow-y: auto;
}

.sidebar.collapsed { width: var(--sidebar-width-collapsed); }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px;
    font-weight: 700;
    font-size: 17px;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-brand .logo-dot {
    width: 28px; height: 28px; border-radius: 8px;
    background: linear-gradient(135deg, var(--color-primary), #60a5fa);
    flex-shrink: 0;
}

.sidebar-nav { padding: 12px 10px; flex: 1; }

.sidebar-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    padding: 14px 12px 6px;
    white-space: nowrap;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: #cbd5e1;
    font-size: 13.5px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-link:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.sidebar-link.active { background: var(--color-primary); color: #fff; }
.sidebar-link .icon { width: 18px; height: 18px; flex-shrink: 0; display: inline-flex; }

.sidebar.collapsed .sidebar-link span.label,
.sidebar.collapsed .sidebar-section-title,
.sidebar.collapsed .sidebar-brand span { display: none; }

.main-area {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.2s ease;
}
.main-area.sidebar-collapsed { margin-left: var(--sidebar-width-collapsed); }

.topbar {
    height: var(--topbar-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar-search {
    flex: 1;
    max-width: 420px;
    position: relative;
}
.topbar-search input {
    width: 100%;
    padding: 9px 14px 9px 36px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-surface-alt);
    font-size: 13.5px;
}
.topbar-search input:focus { outline: none; border-color: var(--color-primary); background: #fff; }
.topbar-search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--color-text-faint); }

.topbar-actions { display: flex; align-items: center; gap: 14px; margin-left: auto; }

.icon-btn {
    width: 38px; height: 38px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    color: var(--color-text-muted);
    position: relative;
    cursor: pointer;
    border: none; background: transparent;
}
.icon-btn:hover { background: var(--color-surface-alt); }
.icon-btn .badge-dot {
    position: absolute; top: 6px; right: 7px;
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--color-danger); border: 2px solid #fff;
}

.user-menu { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-md); }
.user-menu:hover { background: var(--color-surface-alt); }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--color-primary-light); color: var(--color-primary);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; overflow: hidden; flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-menu .name { font-weight: 600; font-size: 13.5px; line-height: 1.2; }
.user-menu .role { font-size: 11.5px; color: var(--color-text-muted); }

.page-content { padding: 24px; max-width: 1440px; width: 100%; margin: 0 auto; }

.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.page-header .breadcrumb { font-size: 12.5px; color: var(--color-text-muted); margin-bottom: 4px; }

/* ---------------------------------------------------------------------
   Komponenty
   --------------------------------------------------------------------- */

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-body { padding: 20px; }
.card-header h2, .card-header h3 { margin: 0; }

.grid { display: grid; gap: 18px; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid-cols-4 { grid-template-columns: repeat(2, 1fr); } .grid-cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .grid-cols-2, .grid-cols-3, .grid-cols-4 { grid-template-columns: 1fr; } }

.stat-card { padding: 18px 20px; }
.stat-card .stat-label { font-size: 12.5px; color: var(--color-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat-card .stat-delta { font-size: 12.5px; margin-top: 4px; font-weight: 600; }
.stat-delta.up { color: var(--color-success); }
.stat-delta.down { color: var(--color-danger); }

.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 16px;
    border-radius: var(--radius-md);
    font-size: 13.5px; font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all .15s ease;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-surface-alt); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: #eef1f5; }
.btn-danger { background: var(--color-danger-light); color: var(--color-danger); }
.btn-danger:hover { background: #fee2e2; }
.btn-success { background: var(--color-success-light); color: var(--color-success); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-icon { padding: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 999px;
    font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em;
}
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-blue { background: var(--color-primary-light); color: var(--color-primary); }
.badge-green { background: var(--color-success-light); color: var(--color-success); }
.badge-yellow { background: var(--color-warning-light); color: var(--color-warning); }
.badge-red { background: var(--color-danger-light); color: var(--color-danger); }
.badge-cyan { background: var(--color-info-light); color: var(--color-info); }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table-responsive { overflow-x: auto; border-radius: var(--radius-lg); }
table.data-table th {
    text-align: left; padding: 12px 16px; background: var(--color-surface-alt);
    font-weight: 600; color: var(--color-text-muted); font-size: 12px;
    text-transform: uppercase; letter-spacing: .03em;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}
table.data-table td {
    padding: 12px 16px; border-bottom: 1px solid var(--color-border); vertical-align: middle;
}
table.data-table tbody tr:hover { background: var(--color-surface-alt); }
table.data-table tbody tr:last-child td { border-bottom: none; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.font-mono { font-family: 'SF Mono', Consolas, monospace; }

.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--color-text-muted); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=tel], input[type=search], select, textarea {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--color-border); border-radius: var(--radius-sm);
    font-size: 13.5px; font-family: inherit; background: #fff; color: var(--color-text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
textarea { resize: vertical; min-height: 80px; }
.help-text { font-size: 12px; color: var(--color-text-faint); margin-top: 4px; }
.field-error { font-size: 12px; color: var(--color-danger); margin-top: 4px; }

.alert { padding: 12px 16px; border-radius: var(--radius-md); font-size: 13.5px; margin-bottom: 16px; display: flex; gap: 10px; align-items: flex-start; }
.alert-success { background: var(--color-success-light); color: #15803d; }
.alert-error { background: var(--color-danger-light); color: #b91c1c; }
.alert-info { background: var(--color-info-light); color: #0e7490; }
.alert-warning { background: var(--color-warning-light); color: #b45309; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--color-text-muted); }

/* Auth pages */
.auth-shell {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(160deg, #0f172a, #1e3a8a 60%, #2563eb);
    padding: 20px;
}
.auth-card { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 400px; padding: 36px 32px; }
.auth-card .logo-dot { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, var(--color-primary), #60a5fa); margin: 0 auto 16px; }

/* Utility */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.w-full { width: 100%; }

.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 8px);
    background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg); min-width: 240px; z-index: 50; display: none; overflow: hidden;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item { display: flex; gap: 10px; align-items: center; padding: 10px 16px; font-size: 13.5px; color: var(--color-text); cursor: pointer; }
.dropdown-item:hover { background: var(--color-surface-alt); text-decoration: none; }
.dropdown-divider { border-top: 1px solid var(--color-border); margin: 4px 0; }

.sidebar-toggle { border: none; background: transparent; cursor: pointer; color: var(--color-text-muted); padding: 8px; border-radius: var(--radius-sm); }
.sidebar-toggle:hover { background: var(--color-surface-alt); }

.mobile-menu-btn { display: none; }

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); width: var(--sidebar-width); z-index: 100; }
    .sidebar.mobile-open { transform: translateX(0); }
    .main-area, .main-area.sidebar-collapsed { margin-left: 0; }
    .mobile-menu-btn { display: inline-flex; }
    .grid-cols-3, .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
}

@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main-area { margin-left: 0 !important; }
    body { background: #fff; }
}
