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

:root {
  --primary:       #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --danger:        #ef4444;
  --danger-hover:  #dc2626;
  --bg:            #f8fafc;
  --card:          #ffffff;
  --border:        #e5e7eb;
  --text:          #111827;
  --muted:         #6b7280;
  --light:         #f1f5f9;
  --radius:        10px;
  --shadow:        0 1px 3px rgba(0,0,0,.08);
  --shadow-md:     0 4px 16px rgba(0,0,0,.1);
  --sidebar-w:     230px;
  --header-h:      58px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5;
  min-height: 100vh;
}
.hidden { display: none !important; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: none;
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background .14s; white-space: nowrap; font-family: inherit;
}
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost     { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--light); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-full      { width: 100%; justify-content: center; }

.icon-btn {
  background: none; border: none; cursor: pointer;
  padding: 4px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.icon-btn:hover { background: var(--light); }
.icon-btn.tiny  { padding: 2px; border-radius: 4px; }

/* ── FORMS ── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; font-weight: 500; }
.field input, .field textarea, .field select {
  padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; color: var(--text); background: #fff;
  outline: none; transition: border-color .14s, box-shadow .14s; font-family: inherit;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.field textarea { resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.req { color: var(--danger); }
.error-msg { color: var(--danger); font-size: 13px; }

/* ── LOGIN ── */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 100%);
}
.login-box {
  background: var(--card); border-radius: 16px; padding: 40px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-md); border: 1px solid var(--border);
}
.login-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 20px; font-weight: 700; margin-bottom: 26px;
}
.login-box h2  { font-size: 21px; font-weight: 700; margin-bottom: 4px; }
.login-sub     { color: var(--muted); margin-bottom: 26px; font-size: 14px; }
#login-form    { display: flex; flex-direction: column; gap: 15px; }

/* ── HEADER ── */
header {
  position: sticky; top: 0; z-index: 20;
  height: var(--header-h);
  background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; gap: 12px;
}
.header-left   { display: flex; align-items: center; gap: 8px; }
.header-right  { display: flex; align-items: center; gap: 10px; }
.logo          { display: flex; align-items: center; gap: 9px; font-size: 17px; font-weight: 700; }
.user-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted);
  padding: 5px 11px; background: var(--light); border-radius: 20px;
}

/* ── LAYOUT ── */
.layout {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--card); border-right: 1px solid var(--border);
  height: 100%; overflow-y: auto;
  padding: 10px 8px 20px;
  display: flex; flex-direction: column; gap: 2px;
  transition: margin-left .2s ease;
}
.layout.sidebar-hidden #sidebar { margin-left: calc(-1 * var(--sidebar-w)); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 8px;
  border: none; background: none; width: 100%; text-align: left;
  cursor: pointer; font-size: 13px; font-weight: 500; color: var(--muted);
  transition: background .12s, color .12s; font-family: inherit;
}
.nav-item:hover  { background: var(--light); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-label       { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }

.nav-count {
  font-size: 11px; font-weight: 600; padding: 1px 7px;
  border-radius: 10px; background: var(--light); color: var(--muted);
  min-width: 22px; text-align: center; flex-shrink: 0;
}
.nav-item.active .nav-count { background: var(--primary); color: #fff; }

.product-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

/* product nav item with hover actions */
.nav-item-wrap { position: relative; }
.product-actions {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  display: none; align-items: center; gap: 1px;
  background: var(--light); border-radius: 6px; padding: 0 2px;
  z-index: 1;
}
.nav-item-wrap:hover .product-actions { display: flex; }
.nav-item-wrap:hover .nav-count       { visibility: hidden; }
.nav-item.active + .product-actions,
.nav-item-wrap:has(.nav-item.active):hover .product-actions {
  background: var(--primary-light);
}

/* sidebar section */
.sidebar-section        { margin-top: 14px; }
.sidebar-section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 2px 10px 7px;
  font-size: 11px; font-weight: 600; color: #9ca3af;
  text-transform: uppercase; letter-spacing: .6px;
}
.no-products-hint {
  font-size: 12px; color: #9ca3af; text-align: center;
  padding: 10px 8px; line-height: 1.7;
}

/* ── MAIN ── */
#main-content { flex: 1; overflow-y: auto; padding: 26px 28px; }

.page-title-row {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 22px; gap: 16px;
}
.page-title-wrap { display: flex; align-items: center; gap: 10px; }
.page-dot { width: 13px; height: 13px; border-radius: 50%; flex-shrink: 0; }
.page-title-row h1 { font-size: 22px; font-weight: 700; }
.subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ── STATS ── */
.stats-row {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 12px; margin-bottom: 22px;
}
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat-label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat-card.s-open   .stat-value { color: #3b82f6; }
.stat-card.s-inprog .stat-value { color: #f59e0b; }
.stat-card.s-pending .stat-value{ color: #8b5cf6; }
.stat-card.s-closed .stat-value { color: #22c55e; }

/* ── FILTERS ── */
.filters-bar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.search-wrap {
  display: flex; align-items: center; gap: 7px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 0 11px; flex: 1; min-width: 160px;
}
.search-wrap input {
  border: none; outline: none; padding: 8px 0;
  font-size: 14px; color: var(--text); background: transparent; width: 100%;
}
.filter-tabs  { display: flex; gap: 4px; flex-wrap: wrap; }
.filter-tab {
  padding: 6px 13px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--card); font-size: 13px; cursor: pointer;
  color: var(--muted); font-weight: 500; transition: all .13s; font-family: inherit;
}
.filter-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.filter-tab:not(.active):hover { background: var(--light); }
.sort-select {
  padding: 7px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: var(--card); color: var(--text);
  cursor: pointer; outline: none; font-family: inherit;
}

/* ── TASK CARDS ── */
#task-list { display: flex; flex-direction: column; gap: 9px; }
.task-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; align-items: flex-start; gap: 12px;
  transition: box-shadow .14s, border-color .14s;
}
.task-card:hover { box-shadow: var(--shadow-md); border-color: #d1d5db; }
.task-card.closed { opacity: .6; }

.task-left  { flex: 1; min-width: 0; }
.task-title {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 480px;
}
.task-card.closed .task-title { text-decoration: line-through; color: var(--muted); }
.task-desc  { font-size: 13px; color: var(--muted); margin-top: 3px; }
.task-meta  { display: flex; align-items: center; gap: 8px; margin-top: 9px; flex-wrap: wrap; }

/* product badge on task card */
.product-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 500;
  border: 1px solid var(--border); background: var(--light); color: var(--muted);
}
.product-badge-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

/* status / priority badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.badge-open        { background: #dbeafe; color: #1d4ed8; }
.badge-in-progress { background: #fef3c7; color: #b45309; }
.badge-pending     { background: #ede9fe; color: #6d28d9; }
.badge-closed      { background: #dcfce7; color: #15803d; }
.badge-high        { background: #fee2e2; color: #b91c1c; }
.badge-medium      { background: #fef9c3; color: #854d0e; }
.badge-low         { background: #f0fdf4; color: #166534; }

.due-badge { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 3px; }
.due-badge.overdue { color: var(--danger); }

.task-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.status-select {
  padding: 4px 7px; border-radius: 6px; border: 1px solid var(--border);
  font-size: 12px; background: var(--card); color: var(--text);
  cursor: pointer; outline: none; font-weight: 500; font-family: inherit;
}

/* ── EMPTY STATE ── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 60px 20px; gap: 8px; text-align: center;
}
.empty-state p    { font-size: 15px; font-weight: 600; color: var(--muted); }
.empty-state span { font-size: 13px; color: #9ca3af; }

/* ── MODALS ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal {
  background: var(--card); border-radius: 14px;
  width: 100%; max-width: 480px;
  box-shadow: 0 20px 40px rgba(0,0,0,.15);
  padding: 26px; display: flex; flex-direction: column; gap: 16px;
}
.modal-sm       { max-width: 380px; }
.modal-header   { display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-desc     { color: var(--muted); font-size: 14px; margin-top: -4px; }
.modal-actions  { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
#task-form, #product-form { display: flex; flex-direction: column; gap: 14px; }

/* ── COLOR SWATCHES ── */
.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 0; }
.color-swatch {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent; transition: transform .12s; outline: none;
}
.color-swatch:hover { transform: scale(1.15); }

/* ── TAG INPUT ── */
.tag-input-wrap {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px;
  padding: 5px 10px; border: 1px solid var(--border); border-radius: 8px;
  cursor: text; min-height: 40px; position: relative; background: #fff;
  transition: border-color .14s, box-shadow .14s;
}
.tag-input-wrap:focus-within {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.tag-chips-selected { display: flex; flex-wrap: wrap; gap: 5px; }
.tag-input-wrap input {
  border: none; outline: none; padding: 3px 4px;
  font-size: 13px; flex: 1; min-width: 130px; background: transparent; font-family: inherit;
}

/* dropdown */
.tag-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow-md); z-index: 50; max-height: 200px; overflow-y: auto;
}
.tag-dd-item {
  padding: 7px 12px; cursor: pointer;
  display: flex; align-items: center; gap: 8px; font-size: 13px;
}
.tag-dd-item:hover { background: var(--light); }
.tag-dd-create { color: var(--primary); font-size: 13px; }
.tag-dd-empty  { padding: 10px 12px; color: var(--muted); font-size: 13px; text-align: center; }

/* chips (used in form + task cards + filter row) */
.tag-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 500;
  white-space: nowrap; line-height: 1.5;
}
.tag-chip-remove {
  background: none; border: none; cursor: pointer; padding: 0;
  font-size: 14px; line-height: 1; opacity: .55; color: inherit; font-family: inherit;
}
.tag-chip-remove:hover { opacity: 1; }

/* ── TAG FILTER ROW ── */
.tag-filter-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 14px; padding: 9px 14px;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
}
.tag-filter-label { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.tag-filter-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--light); color: var(--muted);
  font-size: 12px; font-weight: 500; cursor: pointer;
  transition: all .13s; font-family: inherit; position: relative;
}
.tag-filter-chip:not(.active):hover { border-color: #9ca3af; }
.tag-filter-chip-del {
  background: none; border: none; padding: 0 0 0 2px; cursor: pointer;
  font-size: 13px; line-height: 1; opacity: 0; color: inherit; transition: opacity .12s;
}
.tag-filter-chip:hover .tag-filter-chip-del { opacity: .6; }
.tag-filter-chip:hover .tag-filter-chip-del:hover { opacity: 1; }
.tag-filter-clear {
  font-size: 12px; color: var(--primary); background: none; border: none;
  cursor: pointer; padding: 2px 4px; font-family: inherit; text-decoration: underline;
}

/* task-card tag chips row */
.task-tag-list { display: flex; flex-wrap: wrap; gap: 5px; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  :root { --sidebar-w: 220px; }
  .layout.sidebar-hidden #sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
  #sidebar { position: absolute; z-index: 15; height: calc(100vh - var(--header-h)); box-shadow: var(--shadow-md); }
  #main-content { padding: 18px 14px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .page-title-row { flex-direction: column; align-items: flex-start; }
  .task-title { max-width: 200px; }
  .field-row { grid-template-columns: 1fr; }
  .filters-bar { gap: 8px; }
}
@media (max-width: 480px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .filter-tabs .filter-tab { padding: 5px 10px; font-size: 12px; }
}
