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

:root {
  --c-blue: #4472C4;
  --c-green: #70AD47;
  --c-orange: #ED7D31;
  --c-purple: #7B2D8E;
  --c-red: #C00000;
  --c-teal: #2CA58D;
  --c-yellow: #FFC000;
  --c-grey: #A5A5A5;
  --c-pink: #E84393;
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --text: #333;
  --text-muted: #666;
  --text-faint: #999;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  line-height: 1.45;
}

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

.topbar {
  background: #fff;
  box-shadow: var(--shadow);
  padding: 14px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar .brand { font-size: 18px; font-weight: 700; color: var(--c-blue); }
.topbar nav { display: flex; gap: 20px; align-items: center; }
.topbar nav a { color: var(--text); font-size: 14px; font-weight: 500; }
.topbar nav a.active { color: var(--c-blue); }
.topbar .user-chip { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 10px; }
.topbar .user-chip .role-badge {
  font-size: 11px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 10px;
  background: #eef2f8;
  color: var(--c-blue);
  font-weight: 600;
}
.topbar .user-chip .role-badge.admin { background: #fde8e8; color: var(--c-red); }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 32px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 20px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--c-blue);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: filter 0.12s;
}
.btn:hover { filter: brightness(0.95); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--c-red); }
.btn.small { padding: 5px 10px; font-size: 12px; }

.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 6px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: none;
  border-color: var(--c-blue);
  box-shadow: 0 0 0 3px rgba(68,114,196,0.15);
}

.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
}
.alert.error { background: #fde8e8; color: var(--c-red); }
.alert.success { background: #e7f5e1; color: var(--c-green); }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead th { background: var(--c-blue); color: #fff; padding: 10px 12px; text-align: left; }
.data-table tbody td { padding: 10px 12px; border-bottom: 1px solid #eee; }
.data-table tbody tr:hover { background: #f5f7fa; }
.data-table tbody tr:nth-child(even) { background: #fafbfc; }
.data-table tbody tr:nth-child(even):hover { background: #f0f2f5; }

.tag {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 10px;
  background: #eef2f8;
  color: var(--c-blue);
  font-weight: 600;
}
.tag.admin { background: #fde8e8; color: var(--c-red); }
.tag.inactive { background: #f0f0f0; color: var(--text-faint); }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; font-weight: 600; margin-bottom: 4px; text-align: center; color: var(--c-blue); }
.login-card p.subtitle { font-size: 13px; color: var(--text-muted); text-align: center; margin-bottom: 24px; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { font-size: 18px; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* --- Dashboards & charts --- */
.dashboard-header {
  background: #fff;
  padding: 22px 28px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
}
.dashboard-header .title-block h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.dashboard-header .title-block .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}
.dashboard-header .actions { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }

.date-filter {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}
.date-filter .form-row { margin-bottom: 0; min-width: 150px; }
.date-filter label { font-size: 11px; }

/* Gridstack overrides — cleaner visuals than defaults */
.grid-stack {
  background: transparent;
  min-height: 200px;
}
.grid-stack-item-content {
  inset: 0 !important;
  overflow: visible;
}
.grid-stack > .grid-stack-item > .ui-resizable-handle {
  display: none;
}
.grid-stack.is-editing > .grid-stack-item > .ui-resizable-se,
.grid-stack.is-editing > .grid-stack-item > .ui-resizable-s,
.grid-stack.is-editing > .grid-stack-item > .ui-resizable-e {
  display: block;
}
.grid-stack.is-editing > .grid-stack-item {
  outline: 2px dashed transparent;
  transition: outline-color 0.15s;
}
.grid-stack.is-editing > .grid-stack-item:hover {
  outline-color: var(--c-blue);
}
.grid-stack.is-editing > .grid-stack-item > .grid-stack-item-content {
  cursor: move;
}
.grid-stack-placeholder > .placeholder-content {
  background: rgba(68,114,196,0.08) !important;
  border: 2px dashed var(--c-blue) !important;
  border-radius: var(--radius) !important;
}

/* Dashboard tiles (charts + text) */
.tile {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
.tile.tile-text {
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  padding: 0;
  justify-content: center;
}
.tile.tile-chart {
  padding: 20px;
}

.tile-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}
.tile-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  line-height: 1.3;
}
.tile-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.tile-body {
  flex: 1;
  min-height: 0;
  position: relative;
}
.tile-body > canvas {
  max-height: none !important;
  width: 100% !important;
}

/* Text widgets */
.text-widget {
  padding: 4px 8px;
}
.text-widget.heading {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  padding-bottom: 4px;
  border-bottom: 2px solid var(--c-blue);
  display: inline-block;
}
.text-widget.subheading {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.text-widget.paragraph {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
  white-space: pre-wrap;
}
.text-widget.divider {
  border-top: 1px solid var(--border);
  width: 100%;
  padding: 0;
  margin: 4px 0;
}

/* Edit mode toolbar */
.edit-toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #fffbe6;
  border: 1px solid #f5d87a;
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.edit-toolbar .label { font-weight: 600; font-size: 14px; color: #8a6500; }
.edit-toolbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.tile-edit-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  display: none;
  gap: 4px;
  z-index: 5;
}
.grid-stack.is-editing .tile-edit-badge { display: flex; }
.tile-edit-badge button {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 0;
  box-shadow: var(--shadow);
}
.tile-edit-badge button:hover { color: var(--c-blue); }
.tile-edit-badge button.danger:hover { color: var(--c-red); border-color: var(--c-red); }

/* Add-item modal specific */
.add-type-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.add-type-picker .option {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 18px 14px;
  text-align: center;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.12s, transform 0.12s;
}
.add-type-picker .option:hover {
  border-color: var(--c-blue);
  transform: translateY(-1px);
}
.add-type-picker .option.active {
  border-color: var(--c-blue);
  background: rgba(68,114,196,0.05);
}
.add-type-picker .option .icon {
  font-size: 22px;
  display: block;
  margin-bottom: 4px;
}
.add-type-picker .option .label {
  font-weight: 600;
  font-size: 14px;
}
.add-type-picker .option .hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.chart-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 5px 9px;
  border-radius: 6px;
  font-weight: 600;
}
.icon-btn:hover { background: #f0f2f5; color: var(--c-blue); }

.chart-body {
  flex: 1;
  min-height: 220px;
  position: relative;
}
.chart-body > canvas {
  max-height: 380px !important;
  width: 100% !important;
}

.chart-error {
  padding: 16px;
  text-align: center;
  color: var(--c-red);
  background: #fde8e8;
  border-radius: 8px;
  font-size: 13px;
}
.chart-empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

.kpi-display { text-align: center; padding: 16px 0; display: flex; flex-direction: column; justify-content: center; flex: 1; }
.kpi-display .value { font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-display .sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.kpi-display.color-blue .value { color: var(--c-blue); }
.kpi-display.color-green .value { color: var(--c-green); }
.kpi-display.color-orange .value { color: var(--c-orange); }
.kpi-display.color-purple .value { color: var(--c-purple); }
.kpi-display.color-red .value { color: var(--c-red); }
.kpi-display.color-teal .value { color: var(--c-teal); }
.kpi-display.color-pink .value { color: var(--c-pink); }
.kpi-display.color-yellow .value { color: var(--c-yellow); }
.kpi-display.color-grey .value { color: var(--c-grey); }

.chart-table-wrap {
  max-height: 400px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.chart-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.chart-table thead th {
  background: var(--c-blue); color: #fff;
  padding: 9px 12px; text-align: left; position: sticky; top: 0;
  white-space: nowrap;
}
.chart-table thead th:not(:first-child) { text-align: right; }
.chart-table tbody td {
  padding: 7px 12px; border-bottom: 1px solid #eee;
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart-table tbody td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.chart-table tbody tr:hover { background: #f5f7fa; }
.chart-table tbody tr:nth-child(even) { background: #fafbfc; }

.fullscreen-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 24px;
}
.fullscreen-modal .inner {
  background: #fff;
  border-radius: var(--radius);
  flex: 1;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  position: relative;
}
.fullscreen-modal .inner h3 { margin-bottom: 14px; padding-right: 40px; font-size: 18px; }
.fullscreen-modal .inner .body { flex: 1; position: relative; overflow: auto; }
.fullscreen-modal .close-btn {
  position: absolute;
  top: 16px;
  right: 18px;
  font-size: 20px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
}
.fullscreen-modal .close-btn:hover { background: #f0f2f5; }

.dashboard-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  border-left: 4px solid var(--c-blue);
  text-decoration: none;
  color: var(--text);
  display: block;
}
.dashboard-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.1); text-decoration: none; }
.dashboard-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.dashboard-card p { font-size: 13px; color: var(--text-muted); }
.dashboard-card .meta { font-size: 11px; color: var(--text-faint); margin-top: 10px; }

.dashboards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}
