:root {
  --primary: #5B2C83;
  --primary-dark: #47216A;
  --primary-soft: #F3EBFA;
  --accent: #F28C28;
  --success: #22C55E;
  --success-soft: #E9FBF0;
  --danger: #EF4444;
  --danger-soft: #FDECEC;
  --warning: #F59E0B;
  --warning-soft: #FEF6E7;
  --info: #3B82F6;
  --info-soft: #EAF2FE;
  --bg: #F5F7FA;
  --card-bg: #FFFFFF;
  --border: #E5E7EB;
  --text: #111827;
  --text-muted: #6B7280;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(17,24,39,0.04), 0 1px 8px rgba(17,24,39,0.04);
  --shadow-hover: 0 4px 16px rgba(17,24,39,0.08);
  --sidebar-w: 250px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', 'Segoe UI', -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- App shell: sidebar + topbar + content ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-logo { padding: 20px 20px 16px; display: flex; align-items: center; gap: 10px; }
.sidebar-logo img { height: 34px; width: auto; }
.sidebar-logo .app-name { font-size: 13px; font-weight: 700; color: var(--text); line-height: 1.3; }
.sidebar-logo .app-name small { display: block; font-weight: 500; color: var(--text-muted); font-size: 11px; }

.sidebar-nav { flex: 1; padding: 8px 12px; }
.sidebar-nav .nav-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 700; margin: 18px 10px 6px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 14px; font-weight: 500;
}
.sidebar-nav a:hover { background: var(--primary-soft); color: var(--primary); text-decoration: none; }
.sidebar-nav a.active { background: var(--primary); color: #fff; }
.sidebar-nav a .icon { width: 18px; height: 18px; flex-shrink: 0; display: inline-flex; }
.sidebar-nav a .icon svg { width: 100%; height: 100%; }

.sidebar-help {
  margin: 12px; padding: 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: var(--radius-sm);
  color: #fff;
}
.sidebar-help .title { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.sidebar-help .desc { font-size: 12px; opacity: 0.85; margin-bottom: 10px; }
.sidebar-help a.btn-help {
  display: block; text-align: center; background: rgba(255,255,255,0.15);
  padding: 8px; border-radius: 8px; font-size: 12px; font-weight: 600; color: #fff;
}
.sidebar-help a.btn-help:hover { background: rgba(255,255,255,0.25); text-decoration: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 14px 28px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-size: 20px; font-weight: 700; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 18px; }
.topbar-icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; color: var(--text-muted);
  background: #fff; cursor: pointer; position: relative;
}
.topbar-icon-btn:hover { background: var(--bg); text-decoration: none; }
.topbar-icon-btn svg { width: 18px; height: 18px; }

.user-menu { position: relative; }
.user-menu-trigger { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 6px 4px 4px; border-radius: 999px; }
.user-menu-trigger:hover { background: var(--bg); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-menu-name { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.2; }
.user-menu-role { font-size: 11px; color: var(--text-muted); }
.user-menu-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 8px);
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hover); min-width: 200px; padding: 6px; z-index: 20;
}
.user-menu-dropdown.open { display: block; }
.user-menu-dropdown a { display: block; padding: 9px 12px; border-radius: 8px; font-size: 13px; color: var(--text); }
.user-menu-dropdown a:hover { background: var(--bg); text-decoration: none; }

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

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); transition: box-shadow .15s ease, transform .15s ease;
}
.stat-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.stat-icon {
  width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-icon.tone-primary { background: var(--primary-soft); color: var(--primary); }
.stat-icon.tone-success { background: var(--success-soft); color: var(--success); }
.stat-icon.tone-warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.tone-danger { background: var(--danger-soft); color: var(--danger); }
.stat-icon.tone-info { background: var(--info-soft); color: var(--info); }
.stat-value { font-size: 28px; font-weight: 800; line-height: 1; margin-bottom: 4px; }
.stat-label { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.stat-sub { font-size: 12px; color: var(--text-muted); }

/* ---------- Containers & cards ---------- */
.container { max-width: 1200px; margin: 0 auto; }
.container-narrow { max-width: 440px; margin: 60px auto; padding: 0 20px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.card h1, .card h2 { margin-top: 0; }

h1 { font-size: 24px; font-weight: 800; }
h2 { font-size: 17px; font-weight: 700; }

.btn {
  display: inline-block;
  padding: 11px 20px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  transition: background .12s ease, box-shadow .12s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; text-decoration: none; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: #F3F4F6; color: var(--text); }
.btn-secondary:hover { background: #E5E7EB; text-decoration: none; }
.btn-sm { padding: 6px 14px; font-size: 12px; border-radius: 8px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

form .form-group { margin-bottom: 16px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%;
  padding: 12px 14px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { resize: vertical; min-height: 70px; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: #FAFAFB; }

/* Any table wider than its card scrolls inside the card instead of overflowing the page. */
.table-scroll { overflow-x: auto; }
.table-scroll table { width: max-content; min-width: 100%; }
.sticky-col { position: sticky; left: 0; background: var(--card-bg); z-index: 1; }
tr:hover .sticky-col { background: #FAFAFB; }

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.badge-success { background: var(--success-soft); color: #16803C; }
.badge-danger { background: var(--danger-soft); color: #C22929; }
.badge-warning { background: var(--warning-soft); color: #B45309; }

.alert { padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.alert-success { background: var(--success-soft); color: #16803C; }
.alert-danger { background: var(--danger-soft); color: #C22929; }
.alert-info { background: var(--info-soft); color: #1D4ED8; }

.item-row { display: grid; grid-template-columns: 3fr 0.7fr 2fr 1fr auto; gap: 10px; align-items: start; margin-bottom: 10px; }
.item-row .remove-item { color: var(--danger); cursor: pointer; font-size: 13px; padding-top: 10px; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 10px 0 10px 24px; border-left: 2px solid var(--border); position: relative; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before {
  content: '';
  position: absolute;
  left: -6px; top: 14px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
}
.timeline li.done::before { background: var(--success); }
.timeline li.rejected::before { background: var(--danger); }
.timeline li.current::before { background: var(--primary); }

.text-muted { color: var(--text-muted); }
.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }

.confirm-box { text-align: center; padding: 40px 20px; }
.confirm-box .icon { font-size: 48px; margin-bottom: 12px; }

/* Standardized form letterhead (logo + Form No.), used on every request-form page */
.form-letterhead { margin-bottom: 20px; }
.form-letterhead .letterhead-top { display: flex; justify-content: space-between; align-items: flex-start; }
.form-letterhead .letterhead-logo { height: 46px; width: auto; }
.form-letterhead .letterhead-formno-top { font-size: 12px; color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.form-letterhead .letterhead-divider { border: none; border-top: 1px solid var(--border); margin: 10px 0 12px; }
.form-letterhead .letterhead-formno { font-size: 12px; font-weight: 700; color: var(--primary); letter-spacing: 0.03em; margin-bottom: 2px; }
.form-letterhead .letterhead-title { margin: 0 0 6px; font-size: 24px; }
.form-letterhead .letterhead-meta { margin: 0; font-size: 13px; color: var(--text-muted); font-style: italic; }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; top: 20px; right: 20px; z-index: 999; display: flex; flex-direction: column; gap: 10px; }
.toast {
  min-width: 280px; max-width: 360px; background: #fff; border: 1px solid var(--border);
  border-left: 4px solid var(--info); border-radius: var(--radius-sm); box-shadow: var(--shadow-hover);
  padding: 14px 16px; font-size: 14px; display: flex; align-items: flex-start; gap: 10px;
  animation: toast-in .18s ease-out;
}
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-danger { border-left-color: var(--danger); }
.toast .toast-close { margin-left: auto; cursor: pointer; color: var(--text-muted); font-size: 16px; line-height: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }

/* ---------- Mobile ---------- */
.sidebar-toggle { display: none; }
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 100;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: var(--shadow-hover);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
    background: #fff; cursor: pointer; margin-right: 8px;
  }
  .topbar-title { font-size: 17px; }
  .content { padding: 16px; }
  .user-menu-name, .user-menu-role { display: none; }
}
