/* ============================================================
   FabricERP — Main Stylesheet
   Mobile-first, minimal, high-contrast
   ============================================================ */

:root {
  --brand:       #1a56db;
  --brand-dark:  #1343b0;
  --brand-light: #e8f0fe;
  --success:     #047857;
  --success-bg:  #d1fae5;
  --danger:      #b91c1c;
  --danger-bg:   #fee2e2;
  --warning:     #92400e;
  --warning-bg:  #fef3c7;
  --gray-50:     #f9fafb;
  --gray-100:    #f3f4f6;
  --gray-200:    #e5e7eb;
  --gray-400:    #9ca3af;
  --gray-600:    #4b5563;
  --gray-700:    #374151;
  --gray-900:    #111827;
  --radius:      6px;
  --sidebar-w:   220px;
  --header-h:    52px;
  --shadow:      0 1px 3px rgba(0,0,0,.1);
}

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

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
}

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

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

.app-header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-h);
  background: var(--brand); color: #fff;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; z-index: 200; box-shadow: var(--shadow);
}
.app-header .logo { font-weight: 700; font-size: 1.1rem; color: #fff; letter-spacing: .5px; }
.app-header .spacer { flex: 1; }
.app-header .user-info { font-size: .8rem; opacity: .85; }
.app-header .btn-logout { font-size: .8rem; color: #fff; opacity: .85; }
.app-header .btn-logout:hover { opacity: 1; }

.hamburger {
  display: flex; flex-direction: column; gap: 4px; cursor: pointer;
  background: none; border: none; padding: 6px; color: #fff;
}
.hamburger span { display: block; width: 20px; height: 2px; background: currentColor; border-radius: 2px; }

.sidebar {
  position: fixed; top: var(--header-h); left: 0; bottom: 0;
  width: var(--sidebar-w); background: #fff;
  border-right: 1px solid var(--gray-200);
  overflow-y: auto; z-index: 100;
  transform: translateX(-100%);
  transition: transform .22s ease;
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.3);
  z-index: 99; top: var(--header-h);
}
.sidebar-overlay.open { display: block; }

.nav-section { padding: 8px 0; border-bottom: 1px solid var(--gray-100); }
.nav-section:last-child { border-bottom: none; }
.nav-label {
  font-size: .7rem; font-weight: 600; letter-spacing: .08em;
  color: var(--gray-400); text-transform: uppercase;
  padding: 8px 16px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; color: var(--gray-700); font-size: .875rem;
  cursor: pointer; transition: background .12s;
  border: none; background: none; width: 100%; text-align: left;
  text-decoration: none;
}
.nav-item:hover { background: var(--gray-50); color: var(--brand); text-decoration: none; }
.nav-item.active { background: var(--brand-light); color: var(--brand); font-weight: 500; }
.nav-item .icon { width: 16px; text-align: center; opacity: .7; }

.main-content {
  margin-top: var(--header-h);
  padding: 20px 16px;
  min-height: calc(100vh - var(--header-h));
}

/* Desktop sidebar always visible */
@media (min-width: 768px) {
  .hamburger { display: none; }
  .sidebar { transform: translateX(0); }
  .sidebar-overlay { display: none !important; }
  .main-content { margin-left: var(--sidebar-w); padding: 24px; }
}

/* ---- Cards ---- */
.card {
  background: #fff; border: 1px solid var(--gray-200);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.card-title {
  font-size: 1rem; font-weight: 600; color: var(--gray-900);
  margin-bottom: 16px; padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-100);
}
.page-title { font-size: 1.25rem; font-weight: 600; margin-bottom: 20px; color: var(--gray-900); }

/* ---- KPI Grid ---- */
.kpi-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 600px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }

.kpi-card {
  background: #fff; border: 1px solid var(--gray-200);
  border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: .75rem; color: var(--gray-600); margin-bottom: 4px; }
.kpi-value { font-size: 1.4rem; font-weight: 700; color: var(--gray-900); }
.kpi-value.positive { color: var(--success); }
.kpi-value.negative { color: var(--danger); }
.kpi-sub   { font-size: .75rem; color: var(--gray-400); margin-top: 2px; }

/* ---- Forms ---- */
.form-grid {
  display: grid; gap: 14px;
  grid-template-columns: 1fr;
}
@media (min-width: 600px) { .form-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); } }

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full { grid-column: 1 / -1; }

label { font-size: .8rem; font-weight: 500; color: var(--gray-700); }
label .req { color: var(--danger); margin-left: 2px; }

input[type=text], input[type=number], input[type=date], input[type=password],
input[type=email], select, textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--gray-200); border-radius: var(--radius);
  font-size: .9rem; color: var(--gray-900); background: #fff;
  transition: border-color .15s;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(26,86,219,.1);
}
select { cursor: pointer; }
textarea { resize: vertical; min-height: 70px; }

/* Default indicator on select/input */
.has-default { border-color: var(--brand); background: var(--brand-light); }
.default-badge {
  font-size: .7rem; color: var(--brand); margin-top: 2px;
}

.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; flex-wrap: wrap; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: .875rem; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: all .12s;
  text-decoration: none; white-space: nowrap;
}
.btn-primary   { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); text-decoration: none; color: #fff; }
.btn-secondary { background: #fff; color: var(--gray-700); border-color: var(--gray-200); }
.btn-secondary:hover { background: var(--gray-50); text-decoration: none; }
.btn-danger    { background: var(--danger-bg); color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fecaca; text-decoration: none; }
.btn-success   { background: var(--success-bg); color: var(--success); border-color: #6ee7b7; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Flash messages ---- */
.flash {
  padding: 10px 14px; border-radius: var(--radius);
  font-size: .875rem; margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}
.flash-success { background: var(--success-bg); color: var(--success); border: 1px solid #6ee7b7; }
.flash-error   { background: var(--danger-bg);  color: var(--danger);  border: 1px solid #fca5a5; }
.flash-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #fcd34d; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
  width: 100%; border-collapse: collapse;
  font-size: .85rem;
}
thead th {
  text-align: left; padding: 9px 12px;
  background: var(--gray-50); border-bottom: 2px solid var(--gray-200);
  font-size: .75rem; font-weight: 600; color: var(--gray-600);
  text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--gray-100); }
tbody tr:hover { background: var(--gray-50); }
tbody td { padding: 9px 12px; vertical-align: middle; }
tfoot td { padding: 10px 12px; font-weight: 600; border-top: 2px solid var(--gray-200); }

/* ---- Badges ---- */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 99px;
  font-size: .72rem; font-weight: 600;
}
.badge-open    { background: var(--success-bg); color: var(--success); }
.badge-closed  { background: var(--gray-100);   color: var(--gray-600); }
.badge-knitting{ background: #ede9fe; color: #5b21b6; }
.badge-dyeing  { background: #fce7f3; color: #9d174d; }
.badge-yarn    { background: #fef3c7; color: var(--warning); }
.badge-fabric  { background: #e0f2fe; color: #0369a1; }

/* ---- Filters row ---- */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: flex-end; margin-bottom: 16px;
}
.filters .form-group { min-width: 140px; flex: 1; }
.filters .form-group label { font-size: .75rem; }

/* ---- Empty state ---- */
.empty-state {
  text-align: center; padding: 48px 20px; color: var(--gray-400);
}
.empty-state .icon { font-size: 2rem; margin-bottom: 10px; }
.empty-state p { font-size: .9rem; }

/* ---- Login page ---- */
.login-wrap {
  min-height: 100vh; display: flex;
  align-items: center; justify-content: center;
  background: var(--gray-50); padding: 20px;
}
.login-box {
  width: 100%; max-width: 380px;
  background: #fff; border: 1px solid var(--gray-200);
  border-radius: 10px; padding: 32px 28px;
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo h1 { font-size: 1.5rem; font-weight: 700; color: var(--brand); }
.login-logo p  { font-size: .8rem; color: var(--gray-400); margin-top: 2px; }

/* ---- P&L table ---- */
.pl-table { width: 100%; }
.pl-table td { padding: 8px 4px; }
.pl-table .pl-label { color: var(--gray-600); }
.pl-table .pl-value { text-align: right; font-weight: 500; min-width: 110px; }
.pl-table .pl-section { font-weight: 700; font-size: .75rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--gray-400); padding-top: 16px; }
.pl-table .pl-total td { border-top: 2px solid var(--gray-200); font-weight: 700; padding-top: 10px; }
.pl-positive { color: var(--success); }
.pl-negative { color: var(--danger); }

/* ---- Utility ---- */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-sm     { font-size: .8rem; }
.text-muted  { color: var(--gray-400); }
.text-danger { color: var(--danger); }
.text-success{ color: var(--success); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
.d-flex { display: flex; }
.gap-2  { gap: 8px; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

/* Print */
@media print {
  .app-header, .sidebar, .sidebar-overlay, .btn, .filters, .form-actions { display: none !important; }
  .main-content { margin: 0 !important; padding: 0 !important; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
