/* ============ Reset & Base ============ */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Vazirmatn', Tahoma, sans-serif;
}

:root {
  --primary: #1e3a8a;
  --primary-light: #3b82f6;
  --primary-hover: #1e40af;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --danger: #ef4444;
  --success: #10b981;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-light: #60a5fa;
  --primary-hover: #2563eb;
  --bg: #0f172a;
  --card: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.4);
}

html, body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

body {
  display: flex;
  flex-direction: column;
}

/* ============ Header ============ */
.app-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #fff;
  padding: 20px 16px;
  box-shadow: var(--shadow-lg);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

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

.brand-icon {
  font-size: 32px;
  line-height: 1;
}

.brand h1 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 2px;
}

.subtitle {
  font-size: 12px;
  opacity: 0.85;
  font-weight: 400;
}

.theme-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.theme-btn:hover {
  background: rgba(255,255,255,0.25);
  transform: scale(1.05);
}

/* ============ Tabs ============ */
.tabs {
  display: flex;
  gap: 6px;
  padding: 12px 16px;
  background: var(--card);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 82px;
  z-index: 99;
  -webkit-overflow-scrolling: touch;
}

.tabs::-webkit-scrollbar {
  height: 4px;
}

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

.tabs button {
  flex-shrink: 0;
  padding: 10px 18px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.tabs button:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  transform: translateY(-1px);
}

.tabs button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

/* ============ Content ============ */
.content {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.content h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 18px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.content h3 {
  font-size: 18px;
  font-weight: 700;
  margin: 24px 0 12px;
  color: var(--text);
}

/* ============ Form ============ */
#entry-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  background: var(--card);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  border: 1px solid var(--border);
}

#entry-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

#entry-form input,
#entry-form textarea,
#entry-form select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  transition: all 0.2s;
  width: 100%;
}

#entry-form input:focus,
#entry-form textarea:focus,
#entry-form select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

#entry-form textarea {
  min-height: 80px;
  resize: vertical;
}

#entry-form button[type="submit"] {
  grid-column: 1 / -1;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

#entry-form button[type="submit"]:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

#entry-form button[type="submit"]:active {
  transform: translateY(0);
}

/* ============ Table ============ */
#table-wrap {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 600px;
}

thead {
  background: var(--primary);
  color: #fff;
}

th, td {
  padding: 12px 14px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

tbody tr {
  transition: background 0.15s;
}

tbody tr:hover {
  background: rgba(59,130,246,0.06);
}

tbody tr:last-child td {
  border-bottom: none;
}

td button {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.2s;
}

td button:hover {
  background: var(--danger);
  color: #fff;
}

/* ============ Stock ============ */
#stock-wrap {
  margin-top: 24px;
}

#stock-wrap h3 {
  display: flex;
  align-items: center;
  gap: 8px;
}

#stock-wrap table {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

#stock-wrap thead {
  background: var(--success);
}

#stock-wrap td:nth-child(2) {
  font-weight: 700;
  color: var(--success);
}

/* ============ Footer ============ */
.app-footer {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
  background: var(--card);
}

/* ============ Empty state ============ */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ============ Loading ============ */
.loading {
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ============ Animation ============ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.content > * {
  animation: fadeIn 0.3s ease-out;
}

/* ============ Dashboard ============ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: all 0.25s;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 4px; height: 100%;
  background: var(--primary);
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.stat-card.warn::before { background: #f59e0b; }
.stat-card.danger::before { background: var(--danger); }
.stat-card.success::before { background: var(--success); }
.stat-card.info::before { background: #0ea5e9; }

.stat-icon {
  font-size: 32px;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(59,130,246,0.1);
  flex-shrink: 0;
}

.stat-card.warn .stat-icon { background: rgba(245,158,11,0.12); }
.stat-card.danger .stat-icon { background: rgba(239,68,68,0.12); }
.stat-card.success .stat-icon { background: rgba(16,185,129,0.12); }
.stat-card.info .stat-icon { background: rgba(14,165,233,0.12); }

.stat-body {
  flex: 1;
  min-width: 0;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 500;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
  word-break: break-word;
}

.stat-unit {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  margin-right: 4px;
}

.dashboard-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.dashboard-section h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.mini-list {
  list-style: none;
}

.mini-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  gap: 10px;
}

.mini-list li:last-child {
  border-bottom: none;
}

.mini-list .mini-title {
  font-weight: 600;
  color: var(--text);
}

.mini-list .mini-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.mini-list .badge {
  background: rgba(59,130,246,0.12);
  color: var(--primary);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.stock-bar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  min-width: 0;
}

.stock-bar-track {
  background: var(--border);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
  width: 100%;
}

.stock-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 999px;
  transition: width 0.6s ease-out;
}

/* ============ Tablet ============ */
@media (max-width: 900px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ============ Mobile ============ */
@media (max-width: 640px) {
  /* Header */
  .app-header {
    padding: 12px 12px;
  }

  .header-inner {
    gap: 8px;
  }

  .brand {
    gap: 8px;
    min-width: 0;
    flex: 1;
  }

  .brand-icon {
    font-size: 24px;
  }

  .brand h1 {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .subtitle {
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .theme-btn {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  /* Tabs */
  .tabs {
    top: 66px;
    padding: 8px 10px;
    gap: 5px;
  }

  .tabs button {
    padding: 7px 12px;
    font-size: 12px;
  }

  /* Content */
  .content {
    padding: 12px 10px 24px;
  }

  .content h2 {
    font-size: 17px;
    margin-bottom: 12px;
  }

  .content h3 {
    font-size: 15px;
    margin: 18px 0 10px;
  }

  /* Form */
  #entry-form {
    padding: 14px;
    gap: 10px;
    margin-bottom: 16px;
  }

  #entry-form label {
    font-size: 12px;
  }

  #entry-form input,
  #entry-form textarea,
  #entry-form select {
    padding: 9px 10px;
    font-size: 13px;
  }

  #entry-form button[type="submit"] {
    padding: 11px;
    font-size: 14px;
  }

  /* Table */
  table {
    font-size: 12px;
    min-width: 500px;
  }

  th, td {
    padding: 8px 10px;
  }

  th {
    font-size: 11px;
  }

  td button {
    padding: 4px 8px;
    font-size: 11px;
  }

  /* Dashboard - Compact Horizontal Cards */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
  }

  .stat-card {
    padding: 10px;
    flex-direction: row;
    text-align: right;
    gap: 8px;
    align-items: center;
    border-radius: 10px;
  }

  .stat-card::before {
    width: 3px;
  }

  .stat-icon {
    width: 34px;
    height: 34px;
    font-size: 17px;
    border-radius: 8px;
  }

  .stat-label {
    font-size: 10px;
    margin-bottom: 2px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .stat-value {
    font-size: 15px;
    font-weight: 800;
    line-height: 1.1;
  }

  .stat-unit {
    font-size: 9px;
    margin-right: 2px;
  }

  /* Dashboard Sections */
  .dashboard-section {
    padding: 12px;
    margin-bottom: 12px;
    border-radius: 10px;
  }

  .dashboard-section h3 {
    font-size: 13px;
    margin-bottom: 8px;
  }

  .mini-list li {
    padding: 7px 0;
    font-size: 12px;
    gap: 6px;
  }

  .mini-list .mini-title {
    font-size: 12px;
  }

  .mini-list .mini-meta {
    font-size: 10px;
  }

  .mini-list .badge {
    font-size: 10px;
    padding: 2px 7px;
  }

  .stock-bar-track {
    height: 6px;
  }

  /* Footer */
  .app-footer {
    padding: 14px;
    font-size: 11px;
  }
}

/* ============ Very Small Mobile ============ */
@media (max-width: 380px) {
  .brand h1 {
    font-size: 13px;
  }

  .subtitle {
    display: none;
  }

  .tabs button {
    padding: 6px 10px;
    font-size: 11px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stat-card {
    padding: 10px 12px;
  }

  .stat-icon {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .stat-value {
    font-size: 16px;
  }
}