:root {
  --bg: #0e1016;
  --bg-2: #161a23;
  --bg-3: #1e2430;
  --bg-hover: #242c3c;
  --border: #2a3242;
  --text: #e7eaf2;
  --text-dim: #98a2b6;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.15);
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --purple: #a78bfa;
  --teal: #2dd4bf;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --mono: "Cascadia Mono", "Consolas", "Menlo", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

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

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  margin: 0 0 6px;
  font-weight: 600;
}

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

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
}

.brand .logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
}

.nav {
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  font-weight: 500;
}

.nav a:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}

.nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav .ic {
  width: 18px;
  text-align: center;
  font-size: 15px;
}

.sidebar-foot {
  margin-top: auto;
  padding: 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 26px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar .page-title {
  font-size: 16px;
  font-weight: 600;
}

.topbar .user-box {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 13px;
}

.content {
  padding: 24px 26px 40px;
  max-width: 1200px;
  width: 100%;
}

/* ---------- cards ---------- */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.card h3 {
  font-size: 14px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 14px;
}

/* ---------- stat cards ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.stat {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat .label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.stat .value {
  font-size: 26px;
  font-weight: 700;
  margin-top: 6px;
}

/* ---------- tables ---------- */
.table-wrap {
  overflow-x: auto;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.data th,
table.data td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data th {
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

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

table.data td.dim {
  color: var(--text-dim);
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: var(--mono);
}

/* ---------- badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge.PENDING {
  background: rgba(251, 191, 36, 0.15);
  color: var(--amber);
}

.badge.PROCESSING {
  background: rgba(79, 140, 255, 0.15);
  color: var(--accent);
}

.badge.COMPLETED {
  background: rgba(52, 211, 153, 0.15);
  color: var(--green);
}

.badge.REVIEW {
  background: rgba(167, 139, 250, 0.15);
  color: var(--purple);
}

.badge.CANCELLED {
  background: rgba(248, 113, 113, 0.15);
  color: var(--red);
}

.badge.OWNER {
  background: rgba(167, 139, 250, 0.15);
  color: var(--purple);
}

.badge.STAFF {
  background: rgba(45, 212, 191, 0.15);
  color: var(--teal);
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.dot.on {
  background: var(--green);
}

.dot.off {
  background: var(--red);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: var(--bg-hover);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: #3d7df0;
}

.btn.danger {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.4);
  color: var(--red);
}

.btn.danger:hover {
  background: rgba(248, 113, 113, 0.22);
}

.btn.small {
  padding: 4px 9px;
  font-size: 12px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 5px;
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.field textarea {
  resize: vertical;
  min-height: 70px;
}

/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toolbar input,
.toolbar select {
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

.toolbar .spacer {
  flex: 1;
}

/* ---------- pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 50;
  overflow-y: auto;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
  padding: 20px;
}

.modal.wide {
  max-width: 720px;
}

.modal h3 {
  margin-bottom: 16px;
}

.modal .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ---------- items editor (invoice) ---------- */
.item-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 32px;
  gap: 8px;
  align-items: center;
}

.item-row input {
  width: 100%;
  padding: 7px 9px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

.item-row .line-total {
  text-align: right;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

#items-body input {
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

#items-body td {
  vertical-align: middle;
}

/* ---------- file drop / list ---------- */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
}

.file-item .fname {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item .fmeta {
  color: var(--text-dim);
  font-size: 12px;
}

/* ---------- auth pages ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2134 0%, var(--bg) 60%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.auth-card .brand-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.auth-card .logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
}

.auth-card h1 {
  font-size: 18px;
}

.auth-card .sub {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 18px;
}

/* ---------- toast ---------- */
.toast-box {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  padding: 11px 15px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 360px;
  transition: opacity 0.3s, transform 0.3s;
}

.toast.success {
  border-left-color: var(--green);
}

.toast.error {
  border-left-color: var(--red);
}

.toast.out {
  opacity: 0;
  transform: translateX(10px);
}

/* ---------- misc ---------- */
.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 34px 0;
}

.loading {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 0;
}

.muted {
  color: var(--text-dim);
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.legend .li {
  font-size: 12.5px;
  color: var(--text-dim);
}

.required::after {
  content: " *";
  color: var(--red);
}

@media (max-width: 760px) {
  .sidebar {
    width: 60px;
  }
  .brand span,
  .nav a span.txt,
  .sidebar-foot {
    display: none;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
}
