
:root {
    --bg: #0b0f14;
    --card: #0f1621;
    --muted: #9aa7b5;
    --text: #e5eaf0;
    --primary: #60a5fa;
    --primary-600: #3b82f6;
    --accent: #f472b6;
    --danger: #ef4444;
    --warn: #f59e0b;
    --border: #1f2a37;
    --ink-soft: #9aa7b5;
    --shadow: 0 10px 18px rgba(0, 0, 0, .35);
}

* {
    box-sizing: border-box
}

html, body {
    height: 100%
}

body {
    margin: 0;
    background: radial-gradient(1200px 600px at 10% -10%, rgba(59, 130, 246, .15), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(244, 114, 182, .12), transparent 60%),
    var(--bg);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px
}

header {
    display: none;
}

.brand {
    display: flex;
    gap: 10px;
    align-items: center
}

.brand .logo {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: conic-gradient(from 0deg, #60a5fa, #f472b6, #34d399, #a78bfa);
    box-shadow: var(--shadow)
}

.brand h1 {
    font-size: 18px;
    margin: 0;
    color: var(--text)
}

/* Sidebar Navigation */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 250px;
    height: 100vh;
    background: linear-gradient(180deg, rgba(15, 22, 33, 0.98) 0%, rgba(10, 15, 25, 0.98) 100%);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border);
    padding: 20px 0 20px 0;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 100;
    transition: transform 0.3s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
}

.sidebar.collapsed {
    transform: translateX(-250px);
}

.sidebar .nav {
    padding: 0 12px;
}

/* Scrollbar styling for sidebar */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Sidebar Toggle */
.sidebar-toggle {
    position: fixed;
    top: 20px;
    left: 210px;
    z-index: 101;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 14px;
    transition: all 0.3s ease;
}

.sidebar-toggle:hover {
    background: var(--primary);
    border-color: var(--primary);
}

.sidebar-toggle .icon {
    width: 20px;
    height: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    justify-content: center;
}

.sidebar-toggle .icon span {
    display: block;
    width: 100%;
    height: 2px;
    background: currentColor;
    border-radius: 2px;
    transition: all 0.3s ease;
}

/* Main content with sidebar */
body {
    margin-left: 250px;
    transition: margin-left 0.3s ease;
}

body.sidebar-collapsed {
    margin-left: 0;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.nav a {
    color: var(--text);
    padding: 12px 16px;
    border-radius: 8px;
    text-decoration: none;
    border-left: 3px solid transparent;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s ease;
    margin: 2px 0;
}

.nav a:hover {
    background: rgba(99, 102, 241, 0.1);
    border-left-color: var(--primary);
    transform: translateX(4px);
}

.nav a.active {
    background: rgba(99, 102, 241, 0.2);
    border-left-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}

main {
    padding: 20px
}

.card {
    background: var(--card);
    border-radius: 16px;
    padding: 16px;
    border: 1px solid var(--border);
}

.grid {
    display: grid;
    gap: 16px
}

.grid-2 {
    grid-template-columns:repeat(2, 1fr)
}

.grid-3 {
    grid-template-columns:repeat(3, 1fr)
}

.grid-4 {
    grid-template-columns:repeat(4, 1fr)
}

.grid-5 {
    grid-template-columns:repeat(5, 1fr)
}

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    background: #0b1220;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    outline: none;
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary);
    border-color: var(--primary-600);
}

label {
    display: block;
    font-size: 12px;
    color: var(--ink-soft);
    margin-bottom: 6px
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #0b1220;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
}

.btn:hover {
    filter: brightness(1.02)
}

.btn.primary {
    background: var(--primary);
    border-color: var(--primary-600);
    color: #081018;
    font-weight: 700
}

.btn.ghost {
    background: transparent
}

.btn.danger {
    background: var(--danger);
    border-color: #b91c1c;
    color: #fff
}

.btn.small {
    padding: 6px 10px;
    font-size: 13px
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    border: 1px solid var(--border);
    background: #0b1220;
    color: var(--text);
    white-space: nowrap;
}

.badge.gray {
    background: #0f1621;
    color: var(--muted)
}

.badge.ok {
    background: rgba(16, 185, 129, .12);
    color: #86efac;
    border-color: #064e3b
}

.badge.warn {
    background: rgba(245, 158, 11, .12);
    color: #fbbf24;
    border-color: #7c4a03;
    margin-bottom: 6px;
}

table { width: 100%; border-collapse: separate; border-spacing: 0 8px }

th { font-weight: 600; text-align: left; color: var(--muted); font-size: 13px; padding: 0 12px 8px; text-align: center; }

td { background: #0b1220; border: 1px solid var(--border); border-left: none; border-right: none; padding: 12px; text-align: center; }

tr td:first-child {
    border-top-left-radius: 12px;
    border-bottom-left-radius: 12px;
    border-left: 1px solid var(--border)
}

tr td:last-child {
    border-top-right-radius: 12px;
    border-bottom-right-radius: 12px;
    border-right: 1px solid var(--border)
}

.kpis {
    display: grid;
    grid-template-columns:repeat(3, 1fr);
    gap: 12px
}

.kpi {
    background: #0c0f14;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    box-shadow: var(--shadow)
}

.kpi h3 {
    margin: 0;
    font-size: 12px;
    color: var(--ink-soft)
}

.kpi .n {
    font-size: 22px;
    margin-top: 6px;
    color: var(--text)
}

.pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap
}

.pill {
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    background: #0b1220
}

.pill:hover {
    background: #111827
}

.pill[data-value].active {
    background: var(--primary);
    color: #432a06;
    border-color: var(--primary-600)
}

.footer {
    color: #7a655a;
    font-size: 12px;
    padding: 20px 0
}

.small {
    font-size: 12px;
    color: #7a655a
}

hr.sep {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0
}

.quick-qty {
    display: flex;
    gap: 6px
}

.quick-qty .btn {
    min-width: 44px
}

.sticky-actions {
    position: sticky;
    top: 70px;
    z-index: 5;
    display: flex;
    gap: 8px;
    padding: 8px 0
}

.searchbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap
}

.tabbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap
}

.tabbar a {
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #0b1220;
    text-decoration: none;
    color: var(--text)
}

.tabbar a.active {
    background: #0b1220;
    border-color: var(--primary-600);
    outline: 0
}

/* Ensure horizontal badge rows inside cards on all viewports */
.list-card .row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    font-size: 13px;
    color: var(--muted);
}

.progress {
    height: 10px;
    background: #111827;
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden
}

.progress > span {
    display: block;
    height: 100%
}

.progress .film { background: linear-gradient(90deg, #60a5fa, #3b82f6) }

.progress .press { background: linear-gradient(90deg, #34d399, #10b981) }

/* Compact rows inside project cards */
.list-card .row + .row { margin-top: 6px; }

@media (max-width: 800px) {
    .kpis {
        grid-template-columns:1fr 1fr
    }

    table.table {
        display: none
    }

    .list-cards {
        display: grid;
        gap: 12px
    }

    .list-card {
        background: #0b1220;
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 12px;
        box-shadow: var(--shadow)
    }

    .list-card h4 {
        margin: 0 0 6px 0;
        color: var(--text)
    }

    .list-card .row {
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
        font-size: 13px;
        color: var(--muted)
    }

    .list-card .row .badge {
        margin-right: 6px
    }
}

@media (min-width: 801px) {
    .list-cards {
        display: grid;
        gap: 12px
    }
}

/* Prefer card lists over tables across all viewports */
table.table { display: none }

.pm-bottom {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(11, 18, 32, .95);
    border-top: 1px solid var(--border);
    padding: 8px;
    display: flex;
    gap: 8px;
    justify-content: space-between
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 10px;
    background: #0b1220
}

.toggle input {
    width: auto
}

.pm-wrap {
    display: grid;
    gap: 12px
}

.pm-head {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap
}

.pm-article {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    background: #0f1621;
}

.pm-row {
    display: grid;
    grid-template-columns:repeat(4, 1fr);
    gap: 8px
}

.pm-btn {
    font-size: 18px;
    padding: 16px;
    border-radius: 12px;
    text-align: center
}

.pm-badge {
    display: inline-block;
    min-width: 38px;
    padding: 6px 8px;
    border-radius: 10px;
    background: #0b1220;
    border: 1px solid var(--border);
    color: #fff;
}

@media (max-width: 700px) {
    .pm-row {
        grid-template-columns:repeat(2, 1fr)
    }
}

.quick,
.quick input {
    text-align: center;
    border: 0;
}

/* Flash messages */
.flash { background: rgba(96,165,250,.12); color: #bfdbfe; border: 1px solid #1d4ed8; padding: 10px 12px; border-radius: 10px; }
.flash.error { background: rgba(239,68,68,.12); color: #fecaca; border-color: #7f1d1d; }

/* Enhanced focus states and accessibility */
.btn:focus-visible, 
input:focus-visible, 
select:focus-visible, 
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn:focus-visible {
  box-shadow: 0 0 0 2px var(--primary);
}

/* Improved button states */
.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Better spacing and typography */
h1, h2, h3, h4, h5, h6 {
  line-height: 1.3;
  margin-top: 0;
}

p {
  line-height: 1.6;
}

/* Enhanced form styling */
.form-group {
  margin-bottom: 16px;
}

.form-row {
  display: flex;
  gap: 12px;
  align-items: end;
}

.form-row > * {
  flex: 1;
}

/* Loading states */
.loading {
  position: relative;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Error states */
.error-msg {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
  display: block;
}

.input-error {
  border-color: var(--danger) !important;
  outline-color: var(--danger) !important;
}

/* Success states */
.success-msg {
  color: #10b981;
  font-size: 12px;
  margin-top: 4px;
  display: block;
}

/* Improved mobile touch targets */
@media (max-width: 768px) {
  .btn {
    min-height: 44px;
    padding: 12px 16px;
  }
  
  input, select, textarea {
    min-height: 44px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  .nav a {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --border: #ffffff;
    --text: #ffffff;
    --bg: #000000;
    --card: #111111;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .btn {
    transform: none !important;
  }
}

/* Print styles */
@media print {
  .nav, .btn, .sticky-actions, .pm-bottom {
    display: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
  
  .card {
    border: 1px solid #ccc !important;
    background: white !important;
  }
}

/* Material inventory grid (4 per row) */
.material-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

@media (min-width: 1200px) {
  .material-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.material-tile {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  transition: all 0.2s ease;
  box-shadow: var(--shadow);
}

.material-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, .4);
  border-color: var(--primary);
}

.material-tile-header {
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  min-height: 60px;
}

.material-tile-header h4 {
  margin: 0 10px 0 0;
  font-size: 14px;
  font-weight: 700;
  color: #081018;
  flex: 1;
  background: #fff;
  border-radius: 10px;
  padding: 2px 7px;
  display: inline-block;
}
.material-tile-header .badge {
  background: #fff;
  color: #000;
  border-color: #000;
}
.material-tile-body {
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.material-tile-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.material-tile-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.badge.small {
  font-size: 11px;
  padding: 2px 6px;
}

/* Project Cards Grid */
.project-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.project-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.project-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(99,102,241,0.3);
  border-color: var(--primary);
}

.project-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--border);
}

.project-card-id {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.project-card-title {
  margin: 0 0 8px 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.3;
}

.project-card-customer {
  font-size: 14px;
  color: var(--text-muted);
}

.project-card-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(99,102,241,0.05);
  border-radius: 8px;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.meta-icon {
  font-size: 16px;
}

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

.meta-value {
  color: var(--text);
  font-weight: 600;
}

.project-card-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat-box {
  text-align: center;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.stat-box:hover {
  transform: scale(1.05);
}

.stat-box.stat-ready {
  background: rgba(168,85,247,0.1);
  border-color: var(--accent);
}

.stat-box.stat-done {
  background: rgba(34,197,94,0.1);
  border-color: #22c55e;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-box.stat-ready .stat-value {
  color: var(--accent);
}

.stat-box.stat-done .stat-value {
  color: #22c55e;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.project-card-progress {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.progress-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.progress-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.progress-percent {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
}

.project-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ===== MOBILE RESPONSIVE NAVIGATION ===== */
@media (max-width: 900px) {
  body {
    overflow-x: hidden;
    margin-left: 0 !important;
  }

  .sidebar {
    transform: translateX(-250px);
    z-index: 1001;
  }

  .sidebar.active {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  header {
    margin-left: 0;
  }

  /* Make 3-column grid responsive */
  .grid-3 {
    grid-template-columns: 1fr;
  }
}

/* Mobile Overlay */
.nav-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.nav-overlay.active {
  display: block;
  opacity: 1;
}

.project-card-actions .btn {
  flex: 1;
  min-width: 100px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .project-cards-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .project-card-stats {
    gap: 8px;
  }
  
  .stat-value {
    font-size: 24px;
  }
  
  .project-card-actions .btn {
    flex: none;
    width: 100%;
  }
}
