/**
 * css/app.css
 * -----------------------------------------------------------------------
 * TELEMED Design System — Phase 1
 * Modern, quiet, hospital-appropriate. Apple-like / iOS-modern proportions,
 * subtle liquid glass reserved for a few key elements only (see liquid.css).
 * -----------------------------------------------------------------------
 */

:root {
  --primary: #5944A9;
  --primary-strong: #47368a;
  --primary-tint: #EFECFB;

  --background: #F6F7FB;
  --surface: #FFFFFF;

  --text: #1D1D1F;
  --secondary: #6B7280;
  --border: #E6E8F0;

  --success: #22C55E;
  --warning: #F59E0B;
  --danger: #EF4444;

  --radius-card: 18px;
  --radius-button: 12px;
  --radius-input: 12px;
  --radius-modal: 20px;

  --motion-fast: 150ms ease;
  --motion-base: 200ms ease;
  --motion-slow: 250ms ease;

  --shadow-soft: 0 10px 30px rgba(29, 29, 31, 0.06);
  --shadow-elevated: 0 16px 40px rgba(29, 29, 31, 0.10);

  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-family);
  color: var(--text);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------------------------------------------------------------------
   Typography
--------------------------------------------------------------------- */
h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 { font-size: 28px; line-height: 1.25; }
h2 { font-size: 22px; line-height: 1.3; }
h3 { font-size: 17px; line-height: 1.4; }

p {
  margin: 0;
  line-height: 1.55;
}

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

/* ---------------------------------------------------------------------
   Buttons
--------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border-radius: var(--radius-button);
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--motion-fast), transform var(--motion-fast), box-shadow var(--motion-fast);
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

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

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

.btn-primary[disabled] {
  background: #C9C2E8;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: rgba(29, 29, 31, 0.04);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  height: 36px;
  padding: 0 14px;
  font-size: 13px;
}

/* ---------------------------------------------------------------------
   Form controls
--------------------------------------------------------------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--secondary);
}

.field input {
  height: 46px;
  padding: 0 14px;
  border-radius: var(--radius-input);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 15px;
  color: var(--text);
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
}

.field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-tint);
  outline: none;
}

.field-error {
  font-size: 13px;
  color: var(--danger);
  min-height: 16px;
}

/* ---------------------------------------------------------------------
   Cards
--------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  padding: 24px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.card-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ---------------------------------------------------------------------
   App shell: topbar + sidebar + content
--------------------------------------------------------------------- */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 24px;
}

.topbar-brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--primary);
  display: inline-block;
}

.brand-sub {
  font-weight: 500;
  color: var(--secondary);
  font-size: 13px;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--secondary);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.08);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.topbar-user {
  text-align: right;
  line-height: 1.3;
}

.topbar-user-name {
  font-size: 14px;
  font-weight: 600;
}

.topbar-user-role {
  font-size: 12px;
  color: var(--secondary);
}

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 224px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px 12px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background var(--motion-fast);
}

.sidebar-link:hover {
  background: rgba(29, 29, 31, 0.04);
}

.sidebar-link.active {
  background: var(--primary-tint);
  color: var(--primary-strong);
}

.sidebar-icon {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: currentColor;
  opacity: 0.35;
  flex-shrink: 0;
}

.sidebar-link.active .sidebar-icon {
  opacity: 0.9;
}

.sidebar-logout {
  color: var(--danger);
}

.page-content {
  flex: 1;
  padding: 28px 32px 48px;
  overflow-y: auto;
}

.page-header {
  margin-bottom: 24px;
}

.page-header p {
  color: var(--secondary);
  margin-top: 4px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

/* ---------------------------------------------------------------------
   Placeholder / "coming in a later phase" state
--------------------------------------------------------------------- */
.placeholder-panel {
  border: 1px dashed var(--border);
  border-radius: var(--radius-card);
  padding: 48px 24px;
  text-align: center;
  color: var(--secondary);
  background: rgba(255, 255, 255, 0.5);
}

.placeholder-panel h2 {
  color: var(--text);
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-tint);
  color: var(--primary-strong);
}

/* ---------------------------------------------------------------------
   Toasts
--------------------------------------------------------------------- */
.toast-host {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
}

.toast {
  min-width: 240px;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 14px;
  color: #fff;
  background: var(--text);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--motion-base), transform var(--motion-base);
  box-shadow: var(--shadow-elevated);
}

.toast-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-danger { background: var(--danger); }
.toast-success { background: var(--success); }
.toast-info { background: var(--text); }

/* ---------------------------------------------------------------------
   Responsive
--------------------------------------------------------------------- */
@media (max-width: 900px) {
  .grid-3, .grid-2 {
    grid-template-columns: 1fr;
  }

  .sidebar {
    width: 72px;
  }

  .sidebar-link span:not(.sidebar-icon) {
    display: none;
  }

  .topbar-user {
    display: none;
  }
}

@media (max-width: 640px) {
  .page-content {
    padding: 20px 16px 40px;
  }

  .app-body {
    flex-direction: row;
  }

  .sidebar-footer {
    display: none;
  }
}

/* =======================================================================
   PHASE 2 ADDITIONS
   ======================================================================= */

.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

/* ---------------------------------------------------------------------
   Request cards (telemed.html incoming/outgoing/active lists)
--------------------------------------------------------------------- */
.request-card {
  margin-bottom: 12px;
  padding: 18px;
}

.request-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.request-ref {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.request-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

/* ---------------------------------------------------------------------
   Dashboard status cards (clickable)
--------------------------------------------------------------------- */
.stat-card {
  display: block;
  cursor: pointer;
  transition: transform var(--motion-fast), box-shadow var(--motion-fast);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-elevated);
}

.stat-card .card-value {
  margin-top: 6px;
}

.skeleton {
  border-radius: var(--radius-card);
  background: linear-gradient(100deg, #ECEEF3 30%, #F6F7FB 50%, #ECEEF3 70%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.3s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-card {
  height: 92px;
}

.skeleton-row {
  height: 44px;
  margin-bottom: 8px;
}

/* ---------------------------------------------------------------------
   Filter bar (dashboard + history)
--------------------------------------------------------------------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--secondary);
}

.filter-field input,
.filter-field select {
  height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 13px;
  background: var(--surface);
}

/* ---------------------------------------------------------------------
   History table
--------------------------------------------------------------------- */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
}

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

table.data-table th {
  text-align: left;
  padding: 12px 14px;
  color: var(--secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data-table tbody tr {
  cursor: pointer;
  transition: background var(--motion-fast);
}

table.data-table tbody tr:hover {
  background: rgba(89, 68, 169, 0.04);
}

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

.status-chip {
  display: inline-flex;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.status-chip-WAITING { background: rgba(245, 158, 11, 0.12); color: #92610A; }
.status-chip-ACCEPTED { background: rgba(89, 68, 169, 0.12); color: var(--primary-strong); }
.status-chip-REJECTED, .status-chip-FAILED { background: rgba(239, 68, 68, 0.12); color: #B91C1C; }
.status-chip-CANCELLED { background: rgba(107, 114, 128, 0.12); color: #4B5563; }
.status-chip-EXPIRED { background: rgba(107, 114, 128, 0.12); color: #4B5563; }
.status-chip-ENDED { background: rgba(34, 197, 94, 0.12); color: #15803D; }

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px 0;
  font-size: 13px;
  color: var(--secondary);
}

/* ---------------------------------------------------------------------
   Session detail modal
--------------------------------------------------------------------- */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 20px;
  margin-top: 16px;
}

.detail-grid dt {
  font-size: 12px;
  color: var(--secondary);
  margin-bottom: 2px;
}

.detail-grid dd {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.modal-close {
  position: absolute;
  top: 18px;
  right: 18px;
}

/* ---------------------------------------------------------------------
   Mobile offcanvas sidebar (Phase 2 §47 responsive requirement)
--------------------------------------------------------------------- */
.sidebar-toggle {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 640px) {
  .app-body {
    flex-direction: column;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  #app-sidebar .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform var(--motion-slow);
    flex-direction: column;
    overflow-x: visible;
  }

  #app-sidebar .sidebar-nav {
    flex-direction: column;
  }

  #app-sidebar.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow-elevated);
  }

  .sidebar-backdrop.visible {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(29, 29, 31, 0.32);
    z-index: 30;
  }

  .sidebar-footer {
    display: block;
  }
}

@media (max-width: 900px) and (min-width: 641px) {
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* =======================================================================
   PHASE 5 ADDITIONS
   ======================================================================= */

.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  padding: 10px 16px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--motion-fast), border-color var(--motion-fast);
}

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

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.maintenance-banner {
  background: var(--warning);
  color: #78350F;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
