/* ============================================================================
 * FreelanceTimer License Manager — UI styles (Section 11 — UI/UX Polish)
 * ============================================================================
 * Goals: zero JS-lib spinners, accessible focus, theme variables for light/dark,
 * toasts, modals, skeleton screens. Works on top of Tailwind CDN.
 * ========================================================================== */

/* ── Theme variables (default = dark) ───────────────────────────────────── */
:root {
  --ft-bg:           #020617;   /* slate-950 */
  --ft-surface:      #0f172a;   /* slate-900 */
  --ft-surface-2:    #1e293b;   /* slate-800 */
  --ft-border:       #1e293b;   /* slate-800 */
  --ft-border-soft:  #334155;   /* slate-700 */
  --ft-text:         #f1f5f9;   /* slate-100 */
  --ft-text-muted:   #94a3b8;   /* slate-400 */
  --ft-text-dim:     #64748b;   /* slate-500 */
  --ft-accent:       #6366f1;   /* indigo-500 */
  --ft-accent-hover: #818cf8;   /* indigo-400 */
  --ft-success:      #10b981;
  --ft-danger:       #ef4444;
  --ft-warning:      #f59e0b;
  --ft-info:         #3b82f6;
  --ft-shadow:       0 10px 25px -10px rgba(0,0,0,0.6);
}

html[data-theme="light"] {
  --ft-bg:           #f8fafc;
  --ft-surface:      #ffffff;
  --ft-surface-2:    #f1f5f9;
  --ft-border:       #e2e8f0;
  --ft-border-soft:  #cbd5e1;
  --ft-text:         #0f172a;
  --ft-text-muted:   #475569;
  --ft-text-dim:     #64748b;
  --ft-accent:       #4f46e5;
  --ft-accent-hover: #4338ca;
  --ft-shadow:       0 10px 25px -10px rgba(15,23,42,0.15);
}

html { scroll-behavior: smooth; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  transition: background-color 0.25s ease, color 0.25s ease;
}
code, pre, .font-mono {
  font-family: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, monospace;
}

/* ── Light-mode overrides for Tailwind's slate utilities (admin only) ──── */
html[data-theme="light"] body.bg-slate-950 { background-color: var(--ft-bg) !important; color: var(--ft-text) !important; }
html[data-theme="light"] .bg-slate-950 { background-color: var(--ft-bg) !important; }
html[data-theme="light"] .bg-slate-900 { background-color: var(--ft-surface) !important; }
html[data-theme="light"] .bg-slate-800 { background-color: var(--ft-surface-2) !important; }
html[data-theme="light"] .border-slate-800 { border-color: var(--ft-border) !important; }
html[data-theme="light"] .border-slate-700 { border-color: var(--ft-border-soft) !important; }
html[data-theme="light"] .text-slate-100 { color: var(--ft-text) !important; }
html[data-theme="light"] .text-slate-200 { color: var(--ft-text) !important; }
html[data-theme="light"] .text-slate-300 { color: var(--ft-text-muted) !important; }
html[data-theme="light"] .text-slate-400 { color: var(--ft-text-muted) !important; }
html[data-theme="light"] .text-slate-500 { color: var(--ft-text-dim) !important; }
html[data-theme="light"] .hover\\:bg-slate-800:hover { background-color: var(--ft-surface-2) !important; }
html[data-theme="light"] input, html[data-theme="light"] select, html[data-theme="light"] textarea {
  color: var(--ft-text) !important;
}
html[data-theme="light"] input::placeholder, html[data-theme="light"] textarea::placeholder { color: var(--ft-text-dim) !important; }

table { border-collapse: collapse; }
input:focus, select:focus, textarea:focus, button:focus { outline: none; }
input::placeholder, textarea::placeholder { color: #475569; }

/* ── Accessibility: visible focus rings (Section 11.8) ─────────────────── */
:focus-visible {
  outline: 2px solid var(--ft-accent-hover);
  outline-offset: 2px;
  border-radius: 4px;
}
a:focus-visible, button:focus-visible {
  box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.4);
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ── Existing: copy flash ──────────────────────────────────────────────── */
.copy-flash { animation: copyFlash 0.6s ease; }
@keyframes copyFlash {
  0% { background-color: rgba(16, 185, 129, 0.3); }
  100% { background-color: transparent; }
}

/* ── 11.1: CSS-only spinners ───────────────────────────────────────────── */
.ft-spinner {
  display: inline-block;
  width: 1em; height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: ftSpin 0.7s linear infinite;
  vertical-align: -0.15em;
}
.ft-spinner-sm { width: 0.85em; height: 0.85em; border-width: 2px; }
.ft-spinner-lg { width: 1.5em; height: 1.5em; border-width: 3px; }
@keyframes ftSpin { to { transform: rotate(360deg); } }

/* Button in submitting state */
button[data-ft-submitting="1"], .ft-submitting {
  opacity: 0.7;
  cursor: progress !important;
  pointer-events: none;
}
button[data-ft-submitting="1"] .ft-spinner-slot::before {
  content: '';
  display: inline-block;
  width: 0.85em; height: 0.85em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  margin-right: 0.4em;
  animation: ftSpin 0.7s linear infinite;
  vertical-align: -0.15em;
}

/* 11.1: top-of-page progress bar (page navigation indicator) */
#ft-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: linear-gradient(90deg, var(--ft-accent), var(--ft-accent-hover));
  z-index: 9999;
  transition: width 0.3s ease, opacity 0.3s ease 0.2s;
  opacity: 0; pointer-events: none;
}
#ft-progress.ft-active { opacity: 1; }

/* 11.1: table / list skeleton */
.ft-skeleton {
  background: linear-gradient(90deg,
    var(--ft-surface-2) 0%, var(--ft-border-soft) 50%, var(--ft-surface-2) 100%);
  background-size: 200% 100%;
  animation: ftSkeleton 1.4s ease-in-out infinite;
  border-radius: 4px;
  display: inline-block;
  min-height: 0.85em;
}
@keyframes ftSkeleton {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── 11.3: Toast notifications ─────────────────────────────────────────── */
#ft-toasts {
  position: fixed;
  top: 1rem; right: 1rem;
  z-index: 10000;
  display: flex; flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  max-width: calc(100vw - 2rem);
}
.ft-toast {
  pointer-events: auto;
  min-width: 280px; max-width: 380px;
  background: var(--ft-surface);
  color: var(--ft-text);
  border: 1px solid var(--ft-border);
  border-left: 4px solid var(--ft-info);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  box-shadow: var(--ft-shadow);
  font-size: 0.875rem;
  display: flex; align-items: flex-start; gap: 0.5rem;
  animation: ftToastIn 0.25s ease-out;
}
.ft-toast.ft-toast-out { animation: ftToastOut 0.25s ease-in forwards; }
.ft-toast-success { border-left-color: var(--ft-success); }
.ft-toast-success .ft-toast-icon { color: var(--ft-success); }
.ft-toast-error   { border-left-color: var(--ft-danger); }
.ft-toast-error   .ft-toast-icon { color: var(--ft-danger); }
.ft-toast-warning { border-left-color: var(--ft-warning); }
.ft-toast-warning .ft-toast-icon { color: var(--ft-warning); }
.ft-toast-info    { border-left-color: var(--ft-info); }
.ft-toast-info    .ft-toast-icon { color: var(--ft-info); }
.ft-toast-body  { flex: 1; line-height: 1.4; }
.ft-toast-close {
  background: none; border: 0; color: var(--ft-text-muted);
  cursor: pointer; padding: 0 0 0 0.5rem; font-size: 0.9rem;
}
.ft-toast-close:hover { color: var(--ft-text); }
@keyframes ftToastIn  { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes ftToastOut { to   { transform: translateX(20px); opacity: 0; } }

/* ── 11.2: Confirmation modal ──────────────────────────────────────────── */
.ft-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(2, 6, 23, 0.7);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 9998;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  animation: ftFadeIn 0.15s ease-out;
}
.ft-modal {
  background: var(--ft-surface);
  border: 1px solid var(--ft-border);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 480px; width: 100%;
  box-shadow: var(--ft-shadow);
  color: var(--ft-text);
  animation: ftModalIn 0.2s ease-out;
}
.ft-modal h3 {
  font-size: 1.125rem; font-weight: 600; margin-bottom: 0.5rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.ft-modal p { color: var(--ft-text-muted); font-size: 0.875rem; line-height: 1.5; margin-bottom: 1rem; }
.ft-modal-warn  h3 i { color: var(--ft-warning); }
.ft-modal-danger h3 i { color: var(--ft-danger); }
.ft-modal-input {
  width: 100%; padding: 0.5rem 0.75rem; margin-bottom: 1rem;
  background: var(--ft-bg); color: var(--ft-text);
  border: 1px solid var(--ft-border-soft); border-radius: 6px;
  font-family: inherit; font-size: 0.875rem;
}
.ft-modal-input:focus { border-color: var(--ft-accent); outline: none; }
.ft-modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.ft-modal-actions button {
  padding: 0.5rem 1rem; border-radius: 6px; font-size: 0.875rem; font-weight: 500;
  border: 1px solid var(--ft-border-soft); cursor: pointer;
}
.ft-modal-cancel  { background: transparent; color: var(--ft-text-muted); }
.ft-modal-cancel:hover { background: var(--ft-surface-2); color: var(--ft-text); }
.ft-modal-confirm { background: var(--ft-accent); color: white; border-color: var(--ft-accent); }
.ft-modal-confirm:hover { background: var(--ft-accent-hover); }
.ft-modal-confirm:disabled { opacity: 0.5; cursor: not-allowed; }
.ft-modal-danger .ft-modal-confirm { background: var(--ft-danger); border-color: var(--ft-danger); }
.ft-modal-danger .ft-modal-confirm:hover { background: #dc2626; }

/* On mobile: full-screen modals (11.4) */
@media (max-width: 640px) {
  .ft-modal-backdrop { padding: 0; align-items: stretch; }
  .ft-modal {
    max-width: none; width: 100%;
    border-radius: 0; min-height: 100vh;
    display: flex; flex-direction: column; justify-content: center;
  }
}

@keyframes ftFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes ftModalIn {
  from { transform: translateY(10px) scale(0.97); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* ── 11.4: Mobile sidebar (hamburger) ──────────────────────────────────── */
.ft-sidebar-toggle {
  background: none; border: 1px solid var(--ft-border-soft);
  color: var(--ft-text); padding: 0.4rem 0.6rem;
  border-radius: 6px; cursor: pointer;
}
.ft-sidebar-toggle:hover { background: var(--ft-surface-2); }
#ft-sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 40; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
#ft-sidebar-backdrop.ft-open { opacity: 1; pointer-events: auto; }

@media (max-width: 767px) {
  aside.ft-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 16rem; z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    display: flex !important;
  }
  aside.ft-sidebar.ft-open { transform: translateX(0); }
}

/* ── 11.4: Mobile tables (horizontal scroll + sticky first col) ────────── */
.ft-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 767px) {
  .ft-table-scroll table th:first-child,
  .ft-table-scroll table td:first-child {
    position: sticky; left: 0;
    background: var(--ft-surface);
    z-index: 1;
  }
  .ft-table-scroll table thead th:first-child { z-index: 2; }
}

/* ── 11.5: Theme toggle button ─────────────────────────────────────────── */
.ft-theme-toggle {
  background: none; border: 1px solid var(--ft-border-soft);
  color: var(--ft-text); padding: 0.4rem 0.55rem;
  border-radius: 6px; cursor: pointer; transition: all 0.2s;
  font-size: 0.85rem;
}
.ft-theme-toggle:hover { background: var(--ft-surface-2); }
.ft-theme-toggle .ft-icon-moon { display: none; }
.ft-theme-toggle .ft-icon-sun  { display: inline; }
html[data-theme="light"] .ft-theme-toggle .ft-icon-moon { display: inline; }
html[data-theme="light"] .ft-theme-toggle .ft-icon-sun  { display: none; }

/* ── 11.6: Keyboard shortcut <kbd> styling ─────────────────────────────── */
kbd, .ft-kbd {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  font-family: ui-monospace, "JetBrains Mono", monospace;
  font-size: 0.75rem;
  line-height: 1.4;
  background: var(--ft-surface-2);
  border: 1px solid var(--ft-border-soft);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--ft-text);
}

/* ── 11.7: Empty state ────────────────────────────────────────────────── */
.ft-empty {
  text-align: center;
  padding: 3rem 1.5rem;
  border: 1px dashed var(--ft-border-soft);
  border-radius: 12px;
  background: var(--ft-surface);
}
.ft-empty .ft-empty-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 4rem; height: 4rem; border-radius: 50%;
  background: var(--ft-surface-2);
  color: var(--ft-accent);
  font-size: 1.5rem;
  margin-bottom: 1rem;
}
.ft-empty h4 { font-size: 1rem; font-weight: 600; margin-bottom: 0.5rem; color: var(--ft-text); }
.ft-empty p  { font-size: 0.875rem; color: var(--ft-text-muted); margin-bottom: 1.25rem; }
.ft-empty .ft-empty-actions { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.ft-empty .ft-empty-cta {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: var(--ft-accent); color: white;
  border-radius: 6px; font-size: 0.875rem; font-weight: 500;
  border: 0; cursor: pointer; text-decoration: none;
}
.ft-empty .ft-empty-cta:hover { background: var(--ft-accent-hover); }
.ft-empty .ft-empty-secondary {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: transparent; color: var(--ft-text);
  border: 1px solid var(--ft-border-soft); border-radius: 6px;
  font-size: 0.875rem; cursor: pointer; text-decoration: none;
}
.ft-empty .ft-empty-secondary:hover { background: var(--ft-surface-2); }

/* ── Reduced motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
