/* ============================================================
   Reset + root tokens
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #475569;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --danger: #ef4444;
  --accent: #8b5cf6;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: var(--text);
  min-height: 100vh;
  padding: 20px;
  line-height: 1.5;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
}

/* ============================================================
   Header
   ============================================================ */
header {
  text-align: center;
  margin-bottom: 30px;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

header p {
  color: var(--text-muted);
  margin-top: 6px;
  font-size: 0.95rem;
}

/* ============================================================
   Tabs
   ============================================================ */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  background: var(--surface);
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 10px 16px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
}

.tab.active {
  background: var(--primary);
  color: white;
}

.tab:hover:not(.active) {
  background: var(--surface-2);
  color: var(--text);
}

/* ============================================================
   Layout
   ============================================================ */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
}

.card h2 {
  font-size: 1.15rem;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card h2::before {
  content: "";
  width: 4px;
  height: 20px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: 2px;
}

.panel { display: none; }
.panel.active { display: block; }

/* ============================================================
   Form controls
   ============================================================ */
.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
  font-weight: 500;
}

input[type="date"],
input[type="number"],
input[type="text"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 0.2s;
  font-family: inherit;
}

textarea {
  resize: vertical;
  min-height: 76px;
}

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

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

/* Dark-mode-friendly calendar icon */
input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
  cursor: pointer;
}

/* Weekday picker */
.weekday-picker {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.weekday-picker .day {
  padding: 8px 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: center;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  user-select: none;
  transition: all 0.2s;
}

.weekday-picker .day.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.weekday-picker .day:hover:not(.active) {
  border-color: var(--primary);
  color: var(--text);
}

/* ============================================================
   Buttons
   ============================================================ */
button.primary {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.2s;
  margin-top: 6px;
}

button.primary:hover {
  background: var(--primary-hover);
}

button.secondary {
  width: 100%;
  padding: 12px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.2s;
  margin-top: 10px;
}

button.secondary:hover {
  background: var(--border);
}

.btn-text {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
}

.btn-text:hover { text-decoration: underline; }

.btn-inline {
  padding: 0 14px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.15s;
}

.btn-inline:hover {
  background: var(--border);
  border-color: var(--primary);
}

.btn-inline.danger { color: var(--danger); }
.btn-inline.danger:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--danger);
  color: var(--danger);
}

/* ============================================================
   Result panel
   ============================================================ */
.result {
  margin-top: 20px;
  padding: 18px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(139, 92, 246, 0.1));
  border: 1px solid var(--border);
  border-radius: 10px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.result-row:last-child { border-bottom: none; }

.result-row .label {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.result-row .value {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text);
}

.result-row.highlight .value {
  color: var(--success);
  font-size: 1.25rem;
}

/* ============================================================
   Freelancer multipliers table
   ============================================================ */
.multipliers {
  margin-top: 16px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.multipliers-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-weight: 600;
}

.multipliers-table {
  width: 100%;
  border-collapse: collapse;
}

.multipliers-table th,
.multipliers-table td {
  padding: 8px 10px;
  text-align: right;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.multipliers-table th:first-child,
.multipliers-table td:first-child {
  text-align: left;
}

.multipliers-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

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

.multipliers-table td.mult {
  font-weight: 700;
  color: var(--accent);
}

.multipliers-table td.val {
  color: var(--text);
  font-weight: 500;
}

/* ============================================================
   History lists
   ============================================================ */
.history-section {
  margin-top: 30px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.history-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.history-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  transition: border-color 0.15s, background 0.15s;
}

.history-item.clickable {
  cursor: pointer;
}

.history-item.clickable:hover {
  border-color: var(--primary);
  background: #111c33;
}

.history-item .details {
  flex: 1;
  min-width: 0;
}

.history-item .main {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 3px;
}

.history-item .sub {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.history-item .delete {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  font-size: 1rem;
  border-radius: 4px;
}

.history-item .delete:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* ============================================================
   Misc
   ============================================================ */
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
  font-size: 0.9rem;
}

.hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 4px;
}

.hint code {
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text);
}

.settings-card {
  max-width: 640px;
  margin: 0 auto;
}

.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  font-weight: 600;
  margin: 18px 0 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.section-title:first-child {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

/* ============================================================
   Invoice modal
   ============================================================ */
.invoice-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 100;
  overflow-y: auto;
  padding: 20px;
  display: none;
}

.invoice-modal.active { display: block; }

.invoice-editor {
  max-width: 920px;
  margin: 20px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.invoice-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}

.invoice-editor-header h2 { font-size: 1.15rem; }

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 6px;
}

.close-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.invoice-form {
  padding: 18px 22px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.invoice-form .form-group { margin-bottom: 0; }
.invoice-form .form-group.full { grid-column: 1 / -1; }

.customer-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.customer-row select {
  flex: 1;
  min-width: 0;
}

@media (max-width: 640px) {
  .invoice-form { grid-template-columns: 1fr; }
}

/* Invoice document (the printable part) */
.invoice-document {
  background: white;
  color: #1a1a1a;
  margin: 22px;
  padding: 44px 52px;
  border-radius: 6px;
  font-family: Georgia, "Times New Roman", serif;
}

.invoice-document .inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 22px;
  border-bottom: 2px solid #1a1a1a;
  gap: 20px;
}

.invoice-document .inv-title {
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 3px;
}

.invoice-document .inv-meta {
  text-align: right;
  font-size: 0.9rem;
}

.invoice-document .inv-meta div { margin-bottom: 4px; }

.invoice-document .inv-meta .muted {
  color: #666;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.invoice-document .inv-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin: 26px 0;
}

.invoice-document .inv-party h4 {
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 1.5px;
  color: #666;
  margin-bottom: 8px;
  font-weight: 700;
}

.invoice-document .inv-party .name {
  font-weight: 700;
  margin-bottom: 4px;
  font-size: 1.05rem;
}

.invoice-document .inv-party .addr {
  white-space: pre-line;
  font-size: 0.9rem;
  color: #333;
}

.invoice-document .inv-period {
  background: #f5f5f5;
  padding: 10px 14px;
  border-radius: 4px;
  margin-bottom: 22px;
  font-size: 0.92rem;
}

.invoice-document .inv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
}

.invoice-document .inv-table th {
  text-align: left;
  padding: 11px 12px;
  background: #1a1a1a;
  color: white;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

.invoice-document .inv-table td {
  padding: 14px 12px;
  border-bottom: 1px solid #e5e5e5;
  font-size: 0.95rem;
  vertical-align: top;
}

.invoice-document .inv-table th.num,
.invoice-document .inv-table td.num {
  text-align: right;
  white-space: nowrap;
}

.invoice-document .inv-table td .sub {
  color: #666;
  font-size: 0.8rem;
  margin-top: 4px;
}

.invoice-document .inv-total-row td {
  background: #f5f5f5;
  font-weight: 700;
  font-size: 1.05rem;
  border-bottom: none;
}

.invoice-document .inv-bank {
  margin-top: 28px;
  padding: 14px 16px;
  background: #f5f5f5;
  border-left: 4px solid #1a1a1a;
}

.invoice-document .inv-bank h4 {
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 1.5px;
  margin-bottom: 8px;
  font-weight: 700;
}

.invoice-document .inv-bank .details {
  white-space: pre-line;
  font-size: 0.9rem;
  color: #333;
}

.invoice-document .inv-footer {
  margin-top: 40px;
  text-align: center;
  font-size: 0.82rem;
  color: #666;
  border-top: 1px solid #e5e5e5;
  padding-top: 16px;
}

.invoice-actions {
  padding: 14px 22px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

.invoice-actions button {
  width: auto;
  padding: 10px 18px;
  margin: 0;
}

/* ============================================================
   Print — show only the invoice document
   ============================================================ */
@media print {
  body * { visibility: hidden !important; }
  .invoice-modal,
  .invoice-modal * { visibility: visible !important; }

  .invoice-modal {
    position: absolute !important;
    inset: 0 !important;
    background: white !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  .invoice-editor {
    background: white !important;
    border: none !important;
    max-width: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
  }

  .invoice-editor-header,
  .invoice-form,
  .invoice-actions { display: none !important; }

  .invoice-document {
    margin: 0 !important;
    padding: 20mm !important;
    border-radius: 0 !important;
  }
}
