/* ============================================================
   CSS VARIABLES / THEME
============================================================ */
:root {
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-primary: #4f6ef7;
  --color-primary-dark: #3a57e8;
  --color-danger: #e74c3c;
  --color-danger-dark: #c0392b;
  --color-success: #27ae60;
  --color-text: #1a1d2e;
  --color-text-muted: #6b7280;
  --color-border: #e2e8f0;
  --color-shadow: rgba(0, 0, 0, 0.07);
  --radius: 12px;
  --radius-sm: 6px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --transition: 150ms ease;
}

/* ============================================================
   RESET & BASE
============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  line-height: 1.5;
}

h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 600; margin-bottom: 1rem; }
h3 { font-size: 1rem; font-weight: 600; margin-bottom: .75rem; }

input[type="text"],
input[type="number"] {
  font-family: inherit;
  font-size: .9rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: .5rem .75rem;
  width: 100%;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
input[type="text"]:focus,
input[type="number"]:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, .15);
}
input.invalid {
  border-color: var(--color-danger);
}

/* ============================================================
   BUTTONS
============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-family: inherit;
  font-size: .875rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: .5rem 1rem;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary  { background: var(--color-primary); color: #fff; }
.btn-primary:not(:disabled):hover  { background: var(--color-primary-dark); }

.btn-danger   { background: var(--color-danger); color: #fff; }
.btn-danger:not(:disabled):hover   { background: var(--color-danger-dark); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1.5px solid var(--color-border);
}
.btn-ghost:not(:disabled):hover { background: var(--color-border); color: var(--color-text); }
.btn-ghost.btn-danger { color: var(--color-danger); border-color: var(--color-danger); }
.btn-ghost.btn-danger:not(:disabled):hover { background: var(--color-danger); color: #fff; }

.btn-large { padding: .65rem 1.4rem; font-size: 1rem; }
.btn-sm    { padding: .35rem .75rem; font-size: .8rem; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: .25rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  transition: color var(--transition), background var(--transition);
}
.btn-icon:hover { color: var(--color-danger); background: rgba(231,76,60,.1); }

/* ============================================================
   LAYOUT
============================================================ */
.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 4px var(--color-shadow);
}

.sync-status {
  font-size: .78rem;
  font-weight: 500;
  color: var(--color-text-muted);
}
.sync-status.sync-ok  { color: var(--color-success); }
.sync-status.sync-err { color: var(--color-danger); }

.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Two-column grid for Employees + Tip Out */
.app-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

@media (max-width: 700px) {
  .app-content { grid-template-columns: 1fr; }
  .app-header  { flex-direction: column; align-items: flex-start; }
}

/* ============================================================
   CARD
============================================================ */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px var(--color-shadow);
  padding: 1.5rem;
}

/* ============================================================
   AUTH CARD
============================================================ */
.auth-card {
  max-width: 480px;
  margin: 0 auto;
  text-align: center;
}
.auth-card p {
  color: var(--color-text-muted);
  margin-bottom: 1.5rem;
  font-size: .95rem;
}
.auth-card .btn-primary svg { flex-shrink: 0; }

/* ============================================================
   STATUS BAR
============================================================ */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .85rem 1.25rem;
}
.status-info  { display: flex; flex-direction: column; gap: .1rem; }
.status-email { font-weight: 600; font-size: .9rem; }
.status-sync  { font-size: .78rem; color: var(--color-text-muted); }
.status-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ============================================================
   EMPLOYEES
============================================================ */
.add-employee-row {
  display: flex;
  gap: .5rem;
  margin-bottom: 1rem;
}
.add-employee-row input { flex: 1; }
.add-employee-row .btn  { flex-shrink: 0; }

.employees-list {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.employee-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: .5rem .75rem;
  gap: .5rem;
}
.employee-name { font-size: .9rem; font-weight: 500; }

.empty-state {
  color: var(--color-text-muted);
  font-size: .875rem;
  text-align: center;
  padding: 1rem 0;
}

/* ============================================================
   TIP OUT
============================================================ */
.field-row {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  margin-bottom: 1rem;
}
.field-row label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.field-error {
  font-size: .8rem;
  color: var(--color-danger);
  font-weight: 500;
}

.percentage-rows {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-bottom: .75rem;
}

.pct-row {
  display: grid;
  grid-template-columns: 1fr 90px;
  align-items: center;
  gap: .5rem;
}
.pct-row-name {
  font-size: .9rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pct-row input[type="number"] {
  text-align: right;
}

.pct-sum-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .9rem;
  margin-bottom: 1rem;
  color: var(--color-text-muted);
}
.pct-sum-row strong { color: var(--color-text); }

/* ============================================================
   RESULT AREA
============================================================ */
.result-area {
  margin-top: 1.25rem;
  border-top: 1.5px solid var(--color-border);
  padding-top: 1rem;
}

/* ============================================================
   HISTORY
============================================================ */
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.history-header h2 { margin-bottom: 0; }
.history-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.table-scroll { overflow-x: auto; }

/* ============================================================
   DATA TABLE
============================================================ */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.data-table th {
  text-align: left;
  padding: .5rem .75rem;
  background: var(--color-bg);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-text-muted);
  border-bottom: 1.5px solid var(--color-border);
  white-space: nowrap;
}
.data-table td {
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(79,110,247,.04); }

.data-table td:last-child { text-align: right; }

.amount-cell { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ============================================================
   TOAST
============================================================ */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--color-text);
  color: #fff;
  padding: .65rem 1.25rem;
  border-radius: 2rem;
  font-size: .875rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  z-index: 1000;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
  max-width: calc(100vw - 2rem);
  text-align: center;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--color-success); }
.toast.error   { background: var(--color-danger); }

/* ============================================================
   LOADING OVERLAY
============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(244,246,249,.8);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  backdrop-filter: blur(2px);
}
.loading-overlay.hidden { display: none; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#loading-msg { font-size: .9rem; color: var(--color-text-muted); }

/* ============================================================
   CONFIRM DIALOG
============================================================ */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.dialog-backdrop.hidden { display: none; }

.dialog {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1.75rem;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
}
.dialog h3 { margin-bottom: .5rem; }
.dialog p  { color: var(--color-text-muted); font-size: .9rem; margin-bottom: 1.5rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .65rem; }

/* ============================================================
   UTILITY
============================================================ */
.hidden { display: none !important; }
.saving { opacity: .6; pointer-events: none; }
