/* ============================================================================
   Toggl-QBO Sync — Web Interface Styles
   ============================================================================ */

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --success: #34a853;
  --warning: #f9ab00;
  --danger: #ea4335;
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #202124;
  --text-secondary: #5f6368;
  --border: #dadce0;
  --grey-light: #e0e0e0;
  --red-light: #ffcccc;
  --green-light: #e6f4ea;
  --blue-light: #e8f0fe;
  --sidebar-width: 240px;
  --header-height: 56px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
}

.sidebar-header .subtitle {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.sidebar-header .brand-logo {
  width: 64px;
  height: 64px;
  margin-bottom: 8px;
}

.sidebar-header .brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-item.active {
  background: var(--blue-light);
  color: var(--primary);
  font-weight: 500;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-section {
  padding: 16px 20px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  font-weight: 600;
}

.main {
  flex: 1;
  margin-left: var(--sidebar-width);
}

.header {
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.header h2 {
  font-size: 18px;
  font-weight: 500;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.content {
  padding: 24px;
  max-width: 1200px;
}

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
}

.stat-detail {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  transition: all 0.15s;
}

.btn:hover { background: var(--bg); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-success {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

.btn-danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg);
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

tr:hover td { background: #f5f7f9; }

tr.row-matched td { background: var(--grey-light); }
tr.row-unmapped td { background: var(--red-light); }

/* ---- Forms ---- */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-secondary);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

/* ---- Status badges ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: var(--green-light); color: var(--success); }
.badge-warning { background: #fef7e0; color: #b36b00; }
.badge-danger { background: var(--red-light); color: var(--danger); }
.badge-info { background: var(--blue-light); color: var(--primary); }

/* ---- Progress bar ---- */
.progress {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

.progress-bar-success { background: var(--success); }
.progress-bar-warning { background: var(--warning); }
.progress-bar-danger { background: var(--danger); }

/* ---- Alerts / Toast ---- */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 0.2s ease-out;
  max-width: 400px;
}

.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-info { border-left: 4px solid var(--primary); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ---- Loading ---- */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* ---- Setup screen ---- */
.setup-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  max-width: 480px;
  width: 100%;
  text-align: center;
}

.setup-card h1 {
  font-size: 22px;
  margin-bottom: 8px;
  color: var(--primary);
}

.setup-card p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.setup-card input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
}

.tab {
  padding: 10px 20px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 500;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ---- Mapping cell editing ---- */
td.editable {
  cursor: pointer;
  position: relative;
}
td.editable:hover {
  background: var(--blue-light);
}

/* ---- Connection Status ---- */
.connection-status {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.connection-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.connection-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.connection-dot.connected { background: var(--success); }
.connection-dot.disconnected { background: var(--danger); }

.connection-label {
  font-weight: 500;
}

.connection-detail {
  color: var(--text-secondary);
  font-size: 12px;
}

/* ---- Date Range Inline Form ---- */
.date-range-form {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.date-range-form .form-group {
  margin-bottom: 0;
}

.date-range-form input[type="date"],
.date-range-form input[type="number"] {
  width: auto;
  min-width: 140px;
}

.date-range-form input[type="number"] {
  min-width: 80px;
}

.date-range-current {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* ---- Sync Log Groups ---- */
.log-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}

.log-group-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: background 0.15s;
}

.log-group-header:hover {
  background: var(--blue-light);
}

.log-group.expanded .log-group-header {
  border-bottom-color: var(--border);
}

.log-group-toggle {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: transform 0.2s;
}

.log-group.expanded .log-group-toggle {
  transform: rotate(90deg);
}

.log-group-time {
  font-weight: 500;
  font-size: 14px;
}

.log-group-count {
  color: var(--text-secondary);
  font-size: 13px;
}

.log-group-status {
  margin-left: auto;
  display: flex;
  gap: 8px;
  font-size: 12px;
}

.log-group-status .success {
  color: var(--success);
}

.log-group-status .failed {
  color: var(--danger);
}

.log-group-content {
  display: none;
  padding: 0;
}

.log-group.expanded .log-group-content {
  display: block;
}

.log-group-content table {
  margin: 0;
}

.log-group-content th {
  position: static;
}

/* ---- Mapping Sections ---- */
.mapping-section {
  margin-bottom: 24px;
}

.mapping-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  margin-bottom: 0;
}

.mapping-section-header.unmapped {
  color: var(--danger);
  border-bottom-color: var(--danger);
}

.mapping-section-header.mapped {
  color: var(--success);
  border-bottom-color: var(--success);
}

.mapping-section-icon {
  font-size: 16px;
}

.mapping-section-count {
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
}

.mapping-section-header.unmapped .mapping-section-count {
  background: var(--red-light);
  color: var(--danger);
}

.mapping-section-header.mapped .mapping-section-count {
  background: var(--green-light);
  color: var(--success);
}

/* ---- Mapping Select Dropdown ---- */
.mapping-select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  background: var(--surface);
  cursor: pointer;
}

.mapping-select:hover {
  border-color: var(--primary);
}

.mapping-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--blue-light);
}

/* ---- Empty State ---- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-text {
  font-size: 14px;
}

/* ---- Info Box ---- */
.info-box {
  background: var(--blue-light);
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--primary-dark);
}

.info-box strong {
  font-weight: 600;
}

/* ---- Archived Section ---- */
.mapping-section-header.archived {
  color: var(--text-secondary);
  border-bottom-color: var(--border);
  background: var(--bg);
  padding: 10px 12px;
  border-radius: 6px 6px 0 0;
}

.mapping-section-header.archived .mapping-section-count {
  background: var(--grey-light);
  color: var(--text-secondary);
}

.mapping-section-header .section-toggle {
  margin-right: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.mapping-section-content {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
}

.mapping-section-header.archived + .mapping-section-content {
  background: #fafafa;
}

.mapping-section-header.archived + .mapping-section-content tr td {
  color: var(--text-secondary);
}

/* Pending entries warning badge in archived section */
.mapping-section-header.archived ~ .mapping-section-content .badge-warning {
  margin-left: 8px;
  font-size: 10px;
  cursor: help;
}

/* ---- Flatpickr Overrides ---- */
.flatpickr-calendar {
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  border: 1px solid var(--border);
}

.flatpickr-day.selected {
  background: var(--primary);
  border-color: var(--primary);
}

.flatpickr-day.today {
  border-color: var(--primary);
}

.flatpickr-day:hover {
  background: var(--blue-light);
}
