/* ================================================
   PANCA ERP - Design System
   Industrial green, refined, functional
   ================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  /* Brand colors */
  --green:    #1a7a4a;
  --green-d:  #0f5233;
  --green-l:  #e8f5ee;
  --amber:    #d97706;
  --amber-l:  #fef3c7;
  --red:      #dc2626;
  --red-l:    #fee2e2;
  --blue:     #1d6fb8;
  --blue-l:   #dbeafe;

  /* Neutrals */
  --ink:      #0f1a14;
  --ink-2:    #3d5247;
  --ink-3:    #7a9488;
  --bg:       #f0f4f1;
  --white:    #ffffff;
  --line:     #d4e0d8;
  --line-d:   #b8c9bf;

  /* Typography */
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15, 82, 51, 0.05);
  --shadow:    0 2px 8px rgba(15, 82, 51, 0.08);
  --shadow-md: 0 4px 16px rgba(15, 82, 51, 0.12);
  --shadow-lg: 0 12px 32px rgba(15, 82, 51, 0.16);

  /* Radii */
  --r-sm: 4px;
  --r:    8px;
  --r-lg: 12px;
}

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

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

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

p { margin: 0; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; }

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

.mono { font-family: var(--font-mono); }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--r);
  font-weight: 500;
  font-size: 14px;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary    { background: var(--green-d); color: white; }
.btn-primary:hover { background: var(--green); box-shadow: var(--shadow); }

.btn-secondary  { background: white; color: var(--ink); border-color: var(--line-d); }
.btn-secondary:hover { border-color: var(--green); color: var(--green-d); }

.btn-ghost      { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--green-l); color: var(--green-d); }

.btn-danger     { background: var(--red); color: white; }
.btn-danger:hover { background: #b91c1c; }

.btn-icon       { padding: 8px; }

.btn:disabled   { opacity: 0.5; cursor: not-allowed; }

.btn-block      { width: 100%; }
.btn-sm         { padding: 6px 12px; font-size: 13px; }
.btn-lg         { padding: 12px 20px; font-size: 15px; }

/* ============ FORMS ============ */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  margin-bottom: 6px;
}

.form-label .required { color: var(--red); margin-left: 2px; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-d);
  border-radius: var(--r);
  background: white;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-l);
}

.form-textarea { resize: vertical; min-height: 80px; }
.form-error { color: var(--red); font-size: 12px; margin-top: 4px; }

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--line-d);
  border-radius: 22px;
  transition: 0.2s;
}
.toggle-slider::before {
  position: absolute;
  content: '';
  height: 16px;
  width: 16px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--green); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ============ CARD ============ */
.card {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-body { padding: 20px; }

.card-title { font-size: 16px; font-weight: 600; color: var(--ink); }
.card-subtitle { font-size: 13px; color: var(--ink-3); margin-top: 4px; }

/* ============ BADGES ============ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-mono);
}
.badge-gray  { background: #f3f4f6; color: #4b5563; }
.badge-blue  { background: var(--blue-l); color: var(--blue); }
.badge-amber { background: var(--amber-l); color: var(--amber); }
.badge-teal  { background: #ccfbf1; color: #0d9488; }
.badge-green { background: var(--green-l); color: var(--green-d); }
.badge-red   { background: var(--red-l); color: var(--red); }

/* ============ ALERTS ============ */
.alert {
  padding: 12px 16px;
  border-radius: var(--r);
  border: 1px solid;
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-error   { background: var(--red-l); border-color: #fca5a5; color: #991b1b; }
.alert-success { background: var(--green-l); border-color: #86efac; color: var(--green-d); }
.alert-info    { background: var(--blue-l); border-color: #93c5fd; color: var(--blue); }
.alert-warning { background: var(--amber-l); border-color: #fcd34d; color: #92400e; }

/* ============ APP SHELL (Sidebar + Topbar) ============ */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: white;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  padding: 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand-mark {
  width: 36px;
  height: 36px;
  background: var(--green-d);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-brand-text { line-height: 1.2; }
.sidebar-brand-name { font-size: 14px; font-weight: 600; color: var(--ink); }
.sidebar-brand-sub  { font-size: 11px; color: var(--ink-3); font-family: var(--font-mono); }

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-section {
  padding: 8px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-mono);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--ink-2);
  font-size: 13.5px;
  transition: background 0.1s;
  text-decoration: none;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--green-l);
  color: var(--green-d);
  text-decoration: none;
}

.nav-item.active {
  background: var(--green-l);
  color: var(--green-d);
  font-weight: 500;
  border-left-color: var(--green-d);
}

.nav-item-soon { opacity: 0.4; cursor: default; }
.nav-item-soon:hover { background: transparent; color: var(--ink-2); }

.nav-soon {
  margin-left: auto;
  font-size: 10px;
  color: var(--ink-3);
  font-family: var(--font-mono);
}

.nav-item-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 12px 16px;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--r);
  background: var(--bg);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--green-d);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role { font-size: 11px; color: var(--ink-3); font-family: var(--font-mono); }

.logout-btn {
  width: 100%;
  margin-top: 8px;
  padding: 8px;
  font-size: 12px;
  color: var(--ink-3);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
  transition: all 0.15s;
}
.logout-btn:hover {
  background: var(--red-l);
  color: var(--red);
  border-color: var(--red);
}

/* Main area */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: white;
  border-bottom: 1px solid var(--line);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
}

.topbar-left { flex: 1; min-width: 0; }
.topbar-title { font-size: 16px; font-weight: 600; color: var(--ink); }
.topbar-meta {
  font-size: 12px;
  color: var(--ink-3);
  font-family: var(--font-mono);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 12px;
  font-family: var(--font-mono);
}
.breadcrumb a { color: var(--ink-3); }
.breadcrumb-current { color: var(--ink-2); }
.breadcrumb-sep { color: var(--ink-3); opacity: 0.5; }

.content { flex: 1; padding: 24px; }

/* ============ PAGE HEADER ============ */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-header-info { flex: 1; min-width: 200px; }
.page-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.page-subtitle {
  font-size: 13.5px;
  color: var(--ink-3);
  margin-top: 4px;
}
.page-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ============ TABLE ============ */
.tbl-wrap {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.tbl-toolbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.tbl-search {
  flex: 1;
  min-width: 200px;
  position: relative;
}
.tbl-search input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--line-d);
  border-radius: var(--r);
  font-size: 13.5px;
}
.tbl-search input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-l);
}
.tbl-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--ink-3);
}

.tbl-filter {
  font-size: 13px;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: 6px;
}
.tbl-filter select {
  padding: 6px 10px;
  border: 1px solid var(--line-d);
  border-radius: var(--r);
  font-size: 13px;
  color: var(--ink);
  background: white;
}

.tbl-scroll { overflow-x: auto; }

table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.tbl thead th {
  background: var(--bg);
  text-align: left;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 12px;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: var(--font-mono);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

table.tbl tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  vertical-align: middle;
}

table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover { background: rgba(232, 245, 238, 0.4); }

.tbl-empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--ink-3);
}
.tbl-empty-title {
  font-size: 14px;
  color: var(--ink-2);
  margin-bottom: 4px;
}

.tbl-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  color: var(--ink-2);
  background: transparent;
  cursor: pointer;
  transition: all 0.1s;
  border: 1px solid transparent;
}
.tbl-action-btn:hover {
  background: var(--green-l);
  color: var(--green-d);
}
.tbl-action-btn.danger:hover {
  background: var(--red-l);
  color: var(--red);
}

.tbl-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-3);
  font-family: var(--font-mono);
}

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 26, 20, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: white;
  border-radius: var(--r-lg);
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { transform: translateY(8px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--ink-3);
  padding: 4px;
  border-radius: var(--r-sm);
}
.modal-close:hover { background: var(--bg); color: var(--ink); }

.modal-body { padding: 20px; overflow-y: auto; }

.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--bg);
}

.modal-confirm {
  max-width: 420px;
}

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

.stat-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px 20px;
}

.stat-label {
  font-size: 12px;
  color: var(--ink-3);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--ink);
  letter-spacing: -0.02em;
}

.stat-foot { font-size: 12px; color: var(--ink-3); margin-top: 4px; }

/* ============ MASTER MENU CARDS ============ */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.menu-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 24px;
  cursor: pointer;
  transition: all 0.15s;
  display: block;
  color: inherit;
  text-decoration: none;
}

.menu-card:hover {
  border-color: var(--green);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
}

.menu-card.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.menu-card-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--r);
  background: var(--green-l);
  color: var(--green-d);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.menu-card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}

.menu-card-desc { font-size: 13px; color: var(--ink-3); }
.menu-card-meta {
  margin-top: 12px;
  font-size: 12px;
  color: var(--ink-3);
  font-family: var(--font-mono);
}

/* ============ AUTH LOADING ============ */
.auth-loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.2s;
}
.auth-loading.hidden { opacity: 0; pointer-events: none; }

.auth-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--green-d);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ============ TOAST ============ */
.toast-host {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--ink);
  color: white;
  padding: 12px 16px;
  border-radius: var(--r);
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: 380px;
  animation: toastIn 0.2s ease;
}
.toast.success { background: var(--green-d); }
.toast.error   { background: var(--red); }
.toast.warn    { background: var(--amber); }

@keyframes toastIn {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ============ UTILITIES ============ */
.text-muted    { color: var(--ink-3); }
.text-ink-2    { color: var(--ink-2); }
.text-mono     { font-family: var(--font-mono); }
.text-sm       { font-size: 13px; }
.text-xs       { font-size: 12px; }
.text-lg       { font-size: 16px; }
.text-xl       { font-size: 18px; }
.text-2xl      { font-size: 22px; }

.font-medium   { font-weight: 500; }
.font-semibold { font-weight: 600; }

.flex          { display: flex; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2         { gap: 8px; }
.gap-3         { gap: 12px; }
.gap-4         { gap: 16px; }

.mt-2 { margin-top: 8px; }  .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; }
.mr-2 { margin-right: 8px; }

.hidden { display: none !important; }

@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
