:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1f2430;
  --text-muted: #6b7280;
  --primary: #2f5fdc;
  --primary-dark: #1f3f9e;
  --danger: #d64545;
  --success: #1a9e5c;
  --warning: #c9860c;
  --radius: 8px;
  --sidebar-w: 230px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

/* ---- Layout ---- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: #171b26;
  color: #cfd3dc;
  flex-shrink: 0;
  padding: 20px 0;
}
.sidebar .brand {
  padding: 0 20px 20px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  border-bottom: 1px solid #2b3040;
  margin-bottom: 10px;
}
.sidebar nav a {
  display: block;
  padding: 10px 20px;
  color: #b7bccb;
  font-size: 13.5px;
}
.sidebar nav a:hover { background: #232838; text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar .section-title {
  padding: 16px 20px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #6b7280;
}

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar .user-info { font-size: 13px; color: var(--text-muted); }
.topbar .user-info strong { color: var(--text); }

.content { padding: 24px; max-width: 1200px; }

/* ---- Page header ---- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 10px;
}
.page-header h1 { font-size: 20px; margin: 0; font-weight: 600; }
.page-header p.subtitle { margin: 4px 0 0; color: var(--text-muted); font-size: 13px; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}
.card h2 { font-size: 15px; margin: 0 0 14px; font-weight: 600; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-card .num { font-size: 26px; font-weight: 700; }
.stat-card .label { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

/* ---- Table ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { color: var(--text-muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .02em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }

/* ---- Forms ---- */
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; min-height: 90px; }
.form-group { margin-bottom: 14px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 180px; }

.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.checkbox-item { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 400; }
.checkbox-item input { width: auto; }

/* ---- Buttons ---- */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: #f2f3f5; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b93636; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-open { background: #fdecea; color: var(--danger); }
.badge-progress { background: #fff4de; color: var(--warning); }
.badge-redirect { background: #eae6fb; color: #6b3fd6; }
.badge-done { background: #e6f6ec; color: var(--success); }
.badge-active { background: #e6f6ec; color: var(--success); }
.badge-inactive { background: #eee; color: var(--text-muted); }

/* ---- Flash messages ---- */
.flash { padding: 11px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 13.5px; }
.flash-success { background: #e6f6ec; color: #146c3e; }
.flash-error { background: #fdecea; color: #a13030; }

/* ---- Login page ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #171b26, #232838);
}
.login-box {
  background: #fff;
  border-radius: 10px;
  padding: 36px 34px;
  width: 340px;
}
.login-box h1 { font-size: 18px; margin: 0 0 4px; }
.login-box p { margin: 0 0 22px; color: var(--text-muted); font-size: 13px; }

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

.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.actions-cell { white-space: nowrap; }
.actions-cell form { display: inline; }

/* ---- Notifications (Outlook-style side panel) ---- */
.notif-bell {
  position: relative;
  cursor: pointer;
  font-size: 17px;
  padding: 4px 8px;
  border-radius: 6px;
}
.notif-bell:hover { background: #f2f3f5; }
.notif-dot {
  position: absolute; top: 2px; right: 2px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); display: none;
}
.notif-panel {
  position: fixed; top: 0; right: -360px; width: 340px; height: 100vh;
  background: #fff; border-left: 1px solid var(--border);
  box-shadow: -4px 0 16px rgba(0,0,0,.08);
  transition: right .25s ease; z-index: 200; overflow-y: auto;
}
.notif-panel.open { right: 0; }
.notif-panel-header {
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.notif-panel-header h3 { margin: 0; font-size: 15px; }
.notif-item {
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  font-size: 13px; cursor: pointer;
}
.notif-item:hover { background: #fafbfc; }
.notif-item.unread { background: #f2f6ff; }
.notif-item .notif-type { font-weight: 600; }
.notif-item .notif-meta { color: var(--text-muted); font-size: 12px; margin-top: 3px; }
.notif-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.15); z-index: 190;
  display: none;
}
.notif-overlay.open { display: block; }

.notif-toast {
  position: fixed; top: 18px; right: 18px; width: 300px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 14px 16px; z-index: 300;
  transform: translateX(360px); transition: transform .3s ease;
}
.notif-toast.show { transform: translateX(0); }
.notif-toast .notif-type { font-weight: 600; font-size: 13.5px; }
.notif-toast .notif-meta { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

/* ---- Category tree ---- */
.cat-tree-item { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.cat-indent { color: var(--text-muted); font-family: monospace; }

/* ---- Chart click hint ---- */
.chart-wrap { cursor: pointer; }
.period-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.period-tabs a {
  padding: 6px 14px; border-radius: 6px; font-size: 13px;
  border: 1px solid var(--border); color: var(--text);
}
.period-tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.period-tabs a:hover { text-decoration: none; background: #f2f3f5; }
.period-tabs a.active:hover { background: var(--primary-dark); }

.clickable-stat { cursor: pointer; }
.clickable-stat:hover { border-color: var(--primary); }
