:root {
  --primary: #1e5631;
  --primary-dark: #143d22;
  --primary-light: #e8f3eb;
  --accent: #c59b27;
  --accent-light: #fdf8e7;
  --bg: #f5f7f4;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #dfe5de;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --ok: #15803d;
  --ok-bg: #f0fdf4;
  --shadow: 0 2px 10px rgba(20, 61, 34, 0.07);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Header */
.topbar {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
}
.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.7);
  background: #fff;
}
.brand-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.03em;
}
.brand-sub {
  font-size: 11px;
  opacity: 0.88;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.btn-top {
  background: rgba(255,255,255,0.16);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-top:hover { background: rgba(255,255,255,0.28); }
.month-select-top {
  background: #fff;
  color: var(--primary-dark);
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

/* Container */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 14px 70px;
}

/* Login */
.login-wrap {
  max-width: 440px;
  margin: 28px auto;
  background: var(--card);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: 0 8px 30px rgba(20, 61, 34, 0.1);
  border: 1px solid var(--border);
  text-align: center;
}
.login-logo {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--primary-light);
  margin-bottom: 10px;
}
.login-title {
  font-size: 21px;
  font-weight: 800;
  color: var(--primary-dark);
  margin: 0 0 4px;
}
.login-sub {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 22px;
}
.form-group {
  text-align: left;
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 5px;
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="email"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}
textarea { resize: vertical; min-height: 70px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(0.92); }
.btn-outline { background: #fff; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-ghost { background: #f3f4f6; color: var(--text); }
.btn-ghost:hover { background: #e5e7eb; }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  background: #fff;
  padding: 6px;
  border-radius: 14px;
  border: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
  box-shadow: var(--shadow);
}
.tab-btn {
  flex: 1;
  min-width: 110px;
  background: transparent;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.tab-btn.active {
  background: var(--primary);
  color: #fff;
}

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--primary-dark);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat-box {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 11px; color: var(--muted); font-weight: 700; }
.stat-val { font-size: 20px; font-weight: 800; color: var(--primary-dark); margin-top: 2px; }
.stat-box.warn { background: var(--warn-bg); border-color: #fde68a; }
.stat-box.warn .stat-val { color: var(--warn); }

/* Product Grid */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}
.product-card {
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  transition: border-color 0.15s, background 0.15s;
}
.product-card.featured {
  border-color: var(--accent);
  background: var(--accent-light);
}
.product-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}
.prod-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  margin-bottom: 4px;
}
.prod-cat {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: #e5e7eb;
  color: #374151;
  margin-right: 4px;
}
.prod-name { font-size: 15px; font-weight: 800; color: var(--text); }
.prod-price { font-size: 14px; font-weight: 700; color: var(--primary); }
.qty-ctrl {
  display: flex;
  align-items: center;
  gap: 8px;
}
.qty-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1.5px solid var(--primary);
  background: #fff;
  color: var(--primary);
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
}
.qty-btn:active { background: var(--primary); color: #fff; }
.qty-input {
  width: 68px !important;
  text-align: center;
  font-weight: 800;
  padding: 6px !important;
}

/* Order Cards */
.order-card {
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  background: #fff;
}
.order-card.pending { border-left: 5px solid var(--warn); }
.order-card.shipped { border-left: 5px solid var(--ok); }
.order-card.cancelled { border-left: 5px solid #9ca3af; opacity: 0.72; }
.order-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 999px;
}
.badge-pending { background: var(--warn-bg); color: var(--warn); border: 1px solid #fcd34d; }
.badge-shipped { background: var(--ok-bg); color: var(--ok); border: 1px solid #86efac; }
.badge-cancelled { background: #f3f4f6; color: #6b7280; }
.badge-adjust { background: #ede9fe; color: #6d28d9; }

.order-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.order-items {
  background: #f9fafb;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  margin-bottom: 10px;
}
.order-item-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px dashed #e5e7eb;
}
.order-item-row:last-child { border-bottom: none; }
.order-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.order-total { font-size: 15px; font-weight: 800; color: var(--primary-dark); }

/* Filters */
.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: center;
}
.filter-bar select, .filter-bar input {
  width: auto;
  min-width: 150px;
  padding: 8px 10px;
  font-size: 13px;
}

/* Table */
.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data-table th, table.data-table td {
  border-bottom: 1px solid var(--border);
  padding: 9px 8px;
  text-align: left;
}
table.data-table th {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 800;
  white-space: nowrap;
}
table.data-table td.num, table.data-table th.num { text-align: right; white-space: nowrap; }

/* Document (Invoice & Delivery Note) */
.doc-sheet {
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 28px 30px;
  max-width: 820px;
  margin: 0 auto;
  color: #111827;
}
.doc-title {
  text-align: center;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.35em;
  border-bottom: 3px solid var(--primary);
  padding-bottom: 8px;
  margin-bottom: 20px;
}
.doc-header-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 20px;
  margin-bottom: 18px;
}
.doc-client-name {
  font-size: 20px;
  font-weight: 800;
  border-bottom: 1.5px solid #111827;
  padding-bottom: 4px;
  margin-bottom: 12px;
}
.doc-grand-box {
  background: var(--primary-light);
  border: 2px solid var(--primary);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 10px;
}
.doc-grand-box .lbl { font-size: 13px; font-weight: 700; }
.doc-grand-box .amt { font-size: 22px; font-weight: 800; color: var(--primary-dark); }
.doc-company {
  font-size: 12px;
  line-height: 1.65;
}
.doc-company-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.doc-company-head img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
}
.doc-company-name { font-size: 15px; font-weight: 800; }
table.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  margin-bottom: 14px;
}
table.doc-table th, table.doc-table td {
  border: 1px solid #9ca3af;
  padding: 6px 8px;
}
table.doc-table th {
  background: #f3f6f4;
  font-weight: 800;
  text-align: center;
}
table.doc-table td.num { text-align: right; white-space: nowrap; }
table.doc-table td.center { text-align: center; white-space: nowrap; }
.doc-summary-wrap {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}
table.doc-summary {
  width: 320px;
  border-collapse: collapse;
  font-size: 13px;
}
table.doc-summary th, table.doc-summary td {
  border: 1px solid #9ca3af;
  padding: 6px 10px;
}
table.doc-summary th { background: #f3f6f4; text-align: left; }
table.doc-summary td { text-align: right; font-weight: 700; }
table.doc-summary tr.total-row th,
table.doc-summary tr.total-row td {
  background: var(--primary-light);
  font-size: 15px;
  font-weight: 800;
}
.doc-footer-box {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12px;
  background: #fafafa;
  line-height: 1.7;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.48);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
.modal-box {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 620px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.modal-box.wide { max-width: 880px; }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 17px; color: var(--primary-dark); }
.modal-close {
  background: #f3f4f6;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 18px;
  cursor: pointer;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary-dark);
  color: #fff;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

.alert-err {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 12px;
}
.alert-info {
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 680px) {
  .grid-2, .doc-header-grid { grid-template-columns: 1fr; }
  .doc-sheet { padding: 16px 14px; }
  .doc-title { font-size: 19px; }
}

/* Print */
@media print {
  body { background: #fff !important; }
  .no-print, .topbar, .tabs, .filter-bar, .modal-head, .toast { display: none !important; }
  .container { padding: 0 !important; max-width: 100% !important; }
  .card { border: none !important; box-shadow: none !important; padding: 0 !important; }
  .doc-sheet { border: none !important; padding: 0 !important; max-width: 100% !important; }
  .modal-backdrop { position: static !important; background: #fff !important; padding: 0 !important; display: block !important; }
  .modal-box { box-shadow: none !important; max-height: none !important; overflow: visible !important; padding: 0 !important; max-width: 100% !important; }
}
