:root {
  --blue: #3B82F6;
  --blue-light: #EFF6FF;
  --blue-dark: #2563EB;
  --green: #10B981;
  --green-light: #ECFDF5;
  --red: #EF4444;
  --red-light: #FEF2F2;
  --orange: #F59E0B;
  --orange-light: #FFFBEB;
  --bg: #F1F5F9;
  --white: #FFFFFF;
  --gray-50: #F8FAFC;
  --gray-100: #F1F5F9;
  --gray-200: #E2E8F0;
  --gray-300: #CBD5E1;
  --gray-400: #94A3B8;
  --gray-500: #64748B;
  --gray-700: #334155;
  --gray-900: #0F172A;
  --sidebar-w: 220px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,.06), 0 2px 4px rgba(0,0,0,.04);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  background: var(--bg);
  color: var(--gray-700);
  font-size: 14px;
  line-height: 1.5;
}

.layout {
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 10;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 18px;
  border-bottom: 1px solid var(--gray-100);
}

.logo-icon {
  font-size: 28px;
  line-height: 1;
}

.logo-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-900);
}

.logo-sub {
  font-size: 10px;
  color: var(--gray-400);
  margin-top: 1px;
}

.sidebar-nav {
  padding: 12px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--gray-500);
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s;
}

.nav-item:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

.nav-item.active {
  background: var(--blue-light);
  color: var(--blue);
}

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

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--gray-100);
}

.delivery-status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: var(--gray-100);
  color: var(--gray-500);
}

.delivery-status-badge.on {
  background: var(--green-light);
  color: var(--green);
}

.delivery-status-badge.off {
  background: var(--red-light);
  color: var(--red);
}

/* ===== MAIN CONTENT ===== */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--gray-900);
}

.page-meta {
  font-size: 12px;
  color: var(--gray-400);
  margin-top: 3px;
}

/* ===== CARDS ===== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-500);
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.stat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.stat-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.stat-icon.green { background: var(--green-light); }
.stat-icon.red { background: var(--red-light); }
.stat-icon.orange { background: var(--orange-light); }
.stat-icon.blue { background: var(--blue-light); }

.stat-label {
  font-size: 12px;
  color: var(--gray-500);
  font-weight: 500;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.1;
}

.stat-unit {
  font-size: 13px;
  color: var(--gray-400);
  font-weight: 400;
}

/* ===== TOGGLE ===== */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.toggle-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-700);
}

.toggle-sub {
  font-size: 12px;
  color: var(--gray-400);
  margin-top: 2px;
}

.toggle {
  position: relative;
  width: 48px;
  height: 26px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--gray-300);
  border-radius: 13px;
  transition: background .2s;
}

.toggle input:checked + .toggle-track {
  background: var(--green);
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: left .2s;
}

.toggle input:checked ~ .toggle-thumb {
  left: 25px;
}

/* ===== PROGRESS BAR ===== */
.progress-bar {
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 4px;
  transition: width .3s;
}

/* ===== BADGE ===== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green { background: var(--green-light); color: var(--green); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-blue { background: var(--blue-light); color: var(--blue); }
.badge-gray { background: var(--gray-100); color: var(--gray-500); }
.badge-orange { background: var(--orange-light); color: var(--orange); }

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--gray-200);
}

.tab-btn {
  padding: 10px 18px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-500);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}

.tab-btn:hover { color: var(--gray-700); }

.tab-btn.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

/* ===== TABLE ===== */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
}

td {
  padding: 10px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }

td.nowrap { white-space: nowrap; }
td.muted { color: var(--gray-400); font-size: 12px; }
td.truncate { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== FILTER BAR ===== */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-bar input[type=date] {
  padding: 7px 10px;
  border: 1px solid var(--gray-300);
  border-radius: 7px;
  font-size: 13px;
  color: var(--gray-700);
  background: var(--white);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity .15s, transform .1s;
}

.btn:hover { opacity: .88; }
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--blue); color: white; }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-200); }
.btn-success { background: var(--green); color: white; }
.btn-danger { background: var(--red); color: white; }

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

/* ===== PAGINATION ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  font-size: 12px;
  color: var(--gray-500);
}

.pagination-btns {
  display: flex;
  gap: 4px;
}

.page-btn {
  padding: 5px 10px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 12px;
  color: var(--gray-700);
}

.page-btn:hover { background: var(--gray-100); }
.page-btn.active { background: var(--blue); color: white; border-color: var(--blue); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ===== FORM ===== */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.form-hint {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 4px;
}

.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 13px;
  color: var(--gray-700);
  background: white;
  transition: border-color .15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}

.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 13px;
  color: var(--gray-700);
  background: white;
  resize: vertical;
  min-height: 90px;
  font-family: inherit;
  transition: border-color .15s;
}

.form-textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}

.char-count {
  text-align: right;
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 3px;
}

.radio-group {
  display: flex;
  gap: 16px;
  margin-top: 4px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--gray-700);
}

.radio-label input { cursor: pointer; accent-color: var(--blue); }

/* ===== MANUAL OPS ===== */
.op-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.op-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.op-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-900);
}

.op-desc {
  font-size: 12px;
  color: var(--gray-500);
  margin-bottom: 14px;
}

.op-result {
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  display: none;
}

.op-result.success {
  background: var(--green-light);
  color: #065F46;
  display: block;
}

.op-result.error {
  background: var(--red-light);
  color: #991B1B;
  display: block;
}

.op-result.running {
  background: var(--blue-light);
  color: #1E40AF;
  display: block;
}

/* ===== LOADING / ERROR ===== */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 300px;
  gap: 12px;
  color: var(--gray-400);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--gray-400);
  font-size: 13px;
}

.error-msg {
  padding: 12px 16px;
  background: var(--red-light);
  color: #991B1B;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}

.settings-table td:first-child {
  font-family: monospace;
  font-size: 12px;
  color: var(--blue-dark);
  width: 200px;
}

.settings-table td:nth-child(3) {
  min-width: 200px;
}

.settings-table input.form-input {
  padding: 5px 8px;
  font-size: 12px;
}

.inline-save-btn {
  padding: 4px 12px;
  font-size: 12px;
  border-radius: 6px;
  border: none;
  background: var(--blue);
  color: white;
  cursor: pointer;
  white-space: nowrap;
}

.inline-save-btn:hover { background: var(--blue-dark); }

.saved-flash {
  color: var(--green);
  font-size: 12px;
  margin-left: 6px;
}
