/**
 * KM Approval System — Global Theme
 * Design tokens, base reset, and shared component styles.
 * Loaded by sidebar.js on all pages.
 */

/* ── Google Fonts ──────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Space+Mono:wght@400;700&display=swap');

/* ============================================================
   CSS Variables — Design Tokens
   ============================================================ */
:root {
  /* Brand */
  --brand-green-600: #3d8b5e;
  --brand-green-500: #4a9e6e;
  --brand-green-100: #e8f5ed;
  --brand-green-50: #f0faf4;

  /* Backgrounds */
  --bg-page: #f8faf9;
  --bg-white: #ffffff;
  --bg-hover: #f0f5f2;

  /* Borders */
  --border: #e2e8e4;
  --border-light: #eef2f0;

  /* Text */
  --text-primary: #1a2e22;
  --text-secondary: #5c7066;
  --text-muted: #94a39a;

  /* Status */
  --status-approved: #3d8b5e;
  --status-approved-bg: #e8f5ed;
  --status-pending: #e5883a;
  --status-pending-bg: #fef3e6;
  --status-rejected: #d9534f;
  --status-rejected-bg: #fde8e8;
  --status-returned: #4a8fe5;
  --status-returned-bg: #e6f0fd;

  /* Layout */
  --sidebar-width: 256px;
  --sidebar-collapsed: 68px;
  --header-height: 60px;

  /* Fonts */
  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Space Mono', 'JetBrains Mono', monospace;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(26, 46, 34, 0.04);
  --shadow-md: 0 4px 12px rgba(26, 46, 34, 0.06);
  --shadow-lg: 0 8px 24px rgba(26, 46, 34, 0.08);

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 14px;
}

/* ============================================================
   Base Reset & Typography
   ============================================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ============================================================
   Stat Cards
   ============================================================ */
.km-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.km-stat-card {
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 24px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  cursor: default;
}

.km-stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
}

.km-stat-card--green::before  { background: var(--brand-green-500); }
.km-stat-card--orange::before { background: var(--status-pending); }
.km-stat-card--blue::before   { background: var(--status-returned); }
.km-stat-card--red::before    { background: var(--status-rejected); }
.km-stat-card--purple::before { background: #8b5cf6; }

.km-stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.km-stat-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.km-stat-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.km-stat-card--green  .km-stat-card-icon { background: var(--brand-green-100); color: var(--brand-green-600); }
.km-stat-card--orange .km-stat-card-icon { background: var(--status-pending-bg); color: var(--status-pending); }
.km-stat-card--blue   .km-stat-card-icon { background: var(--status-returned-bg); color: var(--status-returned); }
.km-stat-card--red    .km-stat-card-icon { background: var(--status-rejected-bg); color: var(--status-rejected); }
.km-stat-card--purple .km-stat-card-icon { background: #f3f0ff; color: #8b5cf6; }

.km-stat-card-value {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 6px;
}

.km-stat-card-label {
  font-size: 13px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}

/* ============================================================
   Tables
   ============================================================ */
.km-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.km-table thead th {
  background: var(--bg-page);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.km-table tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}

.km-table tbody tr {
  transition: background 0.15s ease;
}

.km-table tbody tr:hover {
  background: var(--bg-hover);
}

.km-table tbody tr:last-child td {
  border-bottom: none;
}

/* ============================================================
   Status Badges
   ============================================================ */
.km-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.km-badge--approved  { background: var(--status-approved-bg); color: var(--status-approved); }
.km-badge--pending   { background: var(--status-pending-bg);  color: var(--status-pending); }
.km-badge--rejected  { background: var(--status-rejected-bg); color: var(--status-rejected); }
.km-badge--returned  { background: var(--status-returned-bg); color: var(--status-returned); }
.km-badge--draft     { background: #f0f2f1; color: var(--text-secondary); }
.km-badge--submitted { background: var(--status-pending-bg);  color: var(--status-pending); }
.km-badge--active    { background: var(--status-approved-bg); color: var(--status-approved); }
.km-badge--inactive  { background: #f0f2f1; color: var(--text-secondary); }
.km-badge--closed    { background: #f3f4f6; color: #6b7280; }
.km-badge--completed { background: #e8f5e9; color: #2e7d32; }

/* ============================================================
   Announcements
   ============================================================ */
.km-announcements {
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.km-announcements-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
}

.km-announcements-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.km-announcement-item {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.15s ease;
}

.km-announcement-item:hover {
  background: var(--bg-hover);
}

.km-announcement-item:last-child {
  border-bottom: none;
}

.km-announcement-item--pinned {
  border-left: 3px solid var(--brand-green-500);
  background: var(--brand-green-50);
}

.km-announcement-item--pinned:hover {
  background: var(--brand-green-100);
}

.km-announcement-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.km-announcement-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.km-announcement-content {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 8px;
  display: none;
  line-height: 1.6;
}

.km-announcement-item.expanded .km-announcement-content {
  display: block;
}

/* ============================================================
   Section Headers
   ============================================================ */
.km-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.km-section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.km-section-link {
  font-size: 13px;
  color: var(--brand-green-600);
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.km-section-link:hover {
  opacity: 0.7;
}

/* ============================================================
   Cards
   ============================================================ */
.km-card {
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.km-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 16px;
}

.km-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ============================================================
   Admin Only Tag
   ============================================================ */
.km-admin-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--status-pending-bg);
  color: var(--status-pending);
}

/* ============================================================
   Page Layout Helpers
   ============================================================ */
.km-page-header {
  margin-bottom: 28px;
}

.km-page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.km-page-subtitle {
  font-size: 14px;
  color: var(--text-muted);
}

.km-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 768px) {
  .km-grid-2 {
    grid-template-columns: 1fr;
  }

  .km-stat-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .km-stat-card {
    padding: 16px;
  }

  .km-stat-card-value {
    font-size: 22px;
  }
}

@media (max-width: 400px) {
  .km-stat-grid {
    grid-template-columns: 1fr;
  }
}
