/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   CompanyA Intranet — Material Design Light CSS
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */

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

:root {
  --primary: #1976D2;
  --primary-dark: #1565C0;
  --primary-light: #E3F2FD;
  --accent: #FF6D00;
  --surface: #FFFFFF;
  --bg: #F5F5F5;
  --sidebar-bg: #263238;
  --sidebar-text: #CFD8DC;
  --sidebar-active: #FFFFFF;
  --sidebar-hover: #37474F;
  --text: #212121;
  --text-secondary: #757575;
  --border: #E0E0E0;
  --success: #43A047;
  --danger: #E53935;
  --danger-bg: #FFEBEE;
  --info: #1976D2;
  --info-bg: #E3F2FD;
  --warning: #F57F17;
  --shadow-1: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-2: 0 3px 6px rgba(0,0,0,.12), 0 2px 4px rgba(0,0,0,.08);
  --shadow-3: 0 10px 20px rgba(0,0,0,.10), 0 3px 6px rgba(0,0,0,.06);
  --radius: 4px;
  --font: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sidebar-w: 240px;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  margin-bottom: 8px;
}
.brand-mark {
  width: 36px; height: 36px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.brand strong { color: #fff; font-size: 13px; display: block; }
.brand p { font-size: 11px; color: var(--sidebar-text); margin: 0; }

/* 사이드바 메뉴 그룹 */
.nav { flex: 1; padding: 0 8px; }
.nav-group { margin-bottom: 4px; }
.nav-group-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: rgba(255,255,255,.35);
  padding: 16px 12px 4px;
  display: block;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--sidebar-text);
  border-radius: var(--radius);
  font-size: 13px;
  transition: background .15s, color .15s;
  text-decoration: none;
}
.nav a:hover {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
}
.nav a.is-active {
  background: var(--primary);
  color: var(--sidebar-active);
  font-weight: 500;
}
.nav a .material-icon {
  font-size: 18px;
  width: 20px;
  text-align: center;
  opacity: .7;
}
.nav a.is-active .material-icon { opacity: 1; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
}

/* ---------- Main Area ---------- */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  box-shadow: var(--shadow-1);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h1 {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
}
.topbar .muted {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-chip {
  background: var(--primary-light);
  color: var(--primary);
  padding: 4px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
}

/* ---------- Content Area ---------- */
.content-area {
  flex: 1;
  padding: 24px;
}

/* ---------- Alert / Messages ---------- */
.alert {
  background: var(--info-bg);
  color: var(--info);
  border-left: 3px solid var(--info);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  border-radius: var(--radius);
}
.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-left-color: var(--danger);
}

/* ---------- Panel / Card ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  margin-bottom: 24px;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.panel-header h2 {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}
.panel-body { padding: 20px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.6;
}
.btn:hover { text-decoration: none; }
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: var(--shadow-2);
}
.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: #EEEEEE;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: #C62828;
}
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover {
  background: var(--primary-light);
}
.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}
.btn-icon {
  padding: 6px;
  min-width: 32px;
}

/* ---------- Filter Grid ---------- */
.filter-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  align-items: flex-end;
}
.filter-grid .field input,
.filter-grid .field select {
  min-width: 210px;
}
.compact-filter { padding: 12px 20px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: .3px;
}

/* ---------- Form Inputs ---------- */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  width: 100%;
  min-width: 140px;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}
select { cursor: pointer; }

/* Form page layout */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  max-width: 640px;
  margin: 0 auto;
  padding: 24px;
}
.form-card h2 {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 4px;
}
.form-card .muted {
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 20px;
}
.form-row {
  margin-bottom: 16px;
}
.form-row label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.form-row .helptext {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Checkbox list */
.checkbox-list { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
}

/* Django CheckboxSelectMultiple renders as ul > li */
.form-row ul {
  list-style: none;
  padding: 0;
  margin: 4px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}
.form-row ul li label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
}

/* Error list */
.errorlist {
  list-style: none;
  padding: 0;
  margin: 4px 0 0;
}
.errorlist li {
  color: var(--danger);
  font-size: 12px;
}

/* ---------- Data Table ---------- */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead {
  background: #FAFAFA;
  border-bottom: 2px solid var(--border);
}
.data-table th {
  padding: 10px 16px;
  text-align: left;
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
}
.data-table td {
  padding: 10px 16px;
  border-bottom: 1px solid #F0F0F0;
  vertical-align: middle;
}
.data-table tbody tr:hover { background: #FAFAFA; }

/* 총 건수 표시 */
.total-count {
  padding: 8px 20px;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
.total-count strong {
  color: var(--primary);
  font-weight: 600;
}

/* ---------- Actions Row ---------- */
.actions-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap;
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
}
.page-indicator {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ---------- Dashboard Cards ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-1);
}
.stat-card .stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .3px;
  margin-bottom: 6px;
}
.stat-card .stat-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
}

/* ---------- Login Page ---------- */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-3);
  padding: 40px;
  width: 100%;
  max-width: 380px;
}
.login-card h1 {
  font-size: 18px;
  font-weight: 500;
  text-align: center;
  margin-bottom: 24px;
}
.login-card .form-row { margin-bottom: 16px; }
.login-card .btn { width: 100%; padding: 10px; }

/* ---------- Confirm Delete ---------- */
.delete-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  max-width: 480px;
  margin: 40px auto;
  padding: 24px;
  text-align: center;
}
.delete-card h2 {
  font-size: 16px;
  margin-bottom: 12px;
}
.delete-card p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 20px;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.is-open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-3);
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 500; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
}
.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* ---------- Quick-date Buttons ---------- */
.quick-dates {
  display: flex;
  gap: 4px;
  align-items: center;
}
.quick-dates button {
  padding: 4px 10px;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font);
  color: var(--text-secondary);
  transition: all .15s;
}
.quick-dates button:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.quick-dates button.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Tooltip ---------- */
.tooltip-cell {
  position: relative;
  cursor: default;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tooltip-cell:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 0;
  background: #37474F;
  color: #fff;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  max-width: 300px;
  z-index: 10;
  box-shadow: var(--shadow-2);
}

/* ---------- Profit/Loss Colors ---------- */
.text-profit { color: var(--primary) !important; font-weight: 500; }
.text-loss { color: var(--danger) !important; font-weight: 500; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .filter-grid { flex-direction: column; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
