/* ═══════════════════════════════════════════════════
   Agapetec Client Portal — Shared Styles
   ═══════════════════════════════════════════════════ */

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

:root {
  --blue:      #1a50c8;
  --blue-dark: #0e3494;
  --blue-bg:   #f0f4ff;
  --text:      #1a1a2e;
  --muted:     #6b7280;
  --border:    #e5e7eb;
  --bg:        #f8fafc;
  --white:     #ffffff;
  --red:       #ef4444;
  --green:     #22c55e;
  --yellow:    #f59e0b;
  --orange:    #f97316;
  --radius:    8px;
  --shadow:    0 4px 24px rgba(0,0,0,.07);
  --sidebar-w: 240px;
  --topbar-h:  64px;
}

body {
  font-family: 'Inter', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Portal Shell Layout ─────────────────────── */
#portalShell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────── */
.portal-sidebar {
  width: var(--sidebar-w);
  background: #0e1a2e;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform .25s ease;
}

.ps-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.ps-logo img { display: block; height: 32px; width: auto; }

.ps-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: rgba(255,255,255,.35);
  margin-top: 10px;
}

.ps-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.ps-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: rgba(255,255,255,.65);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  cursor: pointer;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}

.ps-nav-item svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }
.ps-nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.ps-nav-item.active { background: rgba(26,80,200,.3); color: #fff; border-left-color: var(--blue); }

.ps-footer {
  padding: 12px 0;
  border-top: 1px solid rgba(255,255,255,.08);
}

.ps-logout { color: rgba(255,100,100,.7); }
.ps-logout:hover { color: #ff6b6b; background: rgba(255,100,100,.07); }

/* ── Main Content Area ──────────────────────── */
.portal-main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Top Bar ─────────────────────────────────── */
.portal-topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 16px;
}

.portal-menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text);
  margin-right: auto;
}

.pt-user { display: flex; align-items: center; gap: 12px; }

.pt-avatar {
  width: 38px; height: 38px;
  background: var(--blue);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; font-weight: 700;
  flex-shrink: 0;
}

.pt-name  { font-size: 14px; font-weight: 600; color: var(--text); }
.pt-biz   { font-size: 12px; color: var(--muted); }

/* ── Page Content ────────────────────────────── */
.portal-content { padding: 32px 28px; flex: 1; }

.portal-page-title { font-size: 22px; font-weight: 800; color: var(--text); margin-bottom: 4px; }
.portal-page-sub   { font-size: 14px; color: var(--muted); margin-bottom: 28px; }

/* ── Stat Cards ──────────────────────────────── */
.portal-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  box-shadow: var(--shadow);
}

.stat-card-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 8px; }
.stat-card-value { font-size: 32px; font-weight: 800; color: var(--text); line-height: 1; }
.stat-card-sub   { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat-card.accent { border-left: 4px solid var(--blue); }
.stat-card.red    { border-left: 4px solid var(--red); }
.stat-card.green  { border-left: 4px solid var(--green); }

/* ── Section Blocks ──────────────────────────── */
.portal-section { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 24px; overflow: hidden; }
.portal-section-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.portal-section-head h3 { font-size: 15px; font-weight: 700; color: var(--text); }
.portal-section-body { padding: 0; }

/* ── Tables ──────────────────────────────────── */
.portal-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.portal-table th { padding: 12px 16px; text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); background: var(--bg); border-bottom: 1px solid var(--border); }
.portal-table td { padding: 14px 16px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
.portal-table tr:last-child td { border-bottom: none; }
.portal-table tr:hover td { background: var(--bg); }
.portal-table a { color: var(--blue); text-decoration: none; font-weight: 600; }
.portal-table a:hover { text-decoration: underline; }

/* ── Badges ──────────────────────────────────── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-yellow { background: #fef9c3; color: #a16207; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-gray   { background: #f3f4f6; color: #6b7280; }

/* ── Buttons ─────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px; background: var(--blue); color: #fff;
  border: none; border-radius: var(--radius); font-size: 14px;
  font-weight: 700; cursor: pointer; text-decoration: none;
  transition: background .2s, transform .15s; font-family: inherit;
}
.btn-primary:hover { background: var(--blue-dark); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px; background: var(--white); color: var(--blue);
  border: 1.5px solid var(--blue); border-radius: var(--radius);
  font-size: 14px; font-weight: 700; cursor: pointer; text-decoration: none;
  transition: background .2s; font-family: inherit;
}
.btn-secondary:hover { background: var(--blue-bg); }

.btn-sm { padding: 6px 14px; font-size: 13px; }

/* ── Alerts ──────────────────────────────────── */
.portal-alert { padding: 14px 18px; border-radius: var(--radius); font-size: 14px; margin-bottom: 20px; }
.portal-alert-error   { background: #fee2e2; color: #b91c1c; border-left: 4px solid var(--red); }
.portal-alert-success { background: #dcfce7; color: #15803d; border-left: 4px solid var(--green); }
.portal-alert-info    { background: var(--blue-bg); color: var(--blue); border-left: 4px solid var(--blue); }

/* ── Loading State ───────────────────────────── */
.portal-loading {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 48px 20px; color: var(--muted); font-size: 14px;
}
.portal-spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty State ─────────────────────────────── */
.portal-empty {
  text-align: center; padding: 56px 20px; color: var(--muted);
}
.portal-empty svg { width: 48px; height: 48px; fill: var(--border); margin-bottom: 16px; }
.portal-empty h4  { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.portal-empty p   { font-size: 14px; }

/* ── Modal ───────────────────────────────────── */
.portal-modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 500;
  align-items: center; justify-content: center;
}
.portal-modal-overlay.open { display: flex; }
.portal-modal {
  background: var(--white); border-radius: 12px;
  padding: 36px 32px; max-width: 540px; width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  max-height: 90vh; overflow-y: auto;
}
.portal-modal h3 { font-size: 18px; font-weight: 800; margin-bottom: 6px; }
.portal-modal p  { font-size: 14px; color: var(--muted); margin-bottom: 22px; }

/* ── Forms ───────────────────────────────────── */
.portal-form-group { margin-bottom: 18px; }
.portal-form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.portal-form-group input,
.portal-form-group select,
.portal-form-group textarea {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: 14px; font-family: inherit; color: var(--text);
  background: var(--white); outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.portal-form-group input:focus,
.portal-form-group select:focus,
.portal-form-group textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26,80,200,.1);
}
.portal-form-group textarea { min-height: 100px; resize: vertical; }
.portal-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ── Ticket Detail ───────────────────────────── */
.ticket-body {
  padding: 20px 22px;
  font-size: 14px; line-height: 1.75; color: var(--text);
  border-bottom: 1px solid var(--border);
}
.ticket-meta-row {
  display: flex; gap: 24px; flex-wrap: wrap;
  padding: 16px 22px; background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--muted);
}
.ticket-meta-row strong { color: var(--text); }

.comment-list { padding: 0 22px; }
.comment { border-bottom: 1px solid var(--border); padding: 18px 0; }
.comment:last-child { border-bottom: none; }
.comment-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.comment-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--blue); color:#fff; display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:700;flex-shrink:0; }
.comment-author { font-size: 13px; font-weight: 700; color: var(--text); }
.comment-date   { font-size: 12px; color: var(--muted); }
.comment-body   { font-size: 14px; color: var(--text); line-height: 1.7; padding-left: 42px; }

/* ── Client Detail (Admin) ──────────────────── */
.cd-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px; flex-wrap: wrap; gap: 12px;
}
.cd-header h1 { font-size: 22px; font-weight: 800; color: var(--text); }
.cd-header-actions { display: flex; gap: 8px; }

.cd-tabs {
  display: flex; gap: 0; border-bottom: 2px solid var(--border);
  margin-bottom: 24px; overflow-x: auto;
}
.cd-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 12px 18px; font-size: 13px; font-weight: 600;
  color: var(--muted); text-decoration: none; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  white-space: nowrap; transition: color .15s, border-color .15s;
  background: none; border-top: none; border-left: none; border-right: none;
  font-family: inherit;
}
.cd-tab:hover { color: var(--text); }
.cd-tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.cd-tab .tab-count {
  background: var(--blue); color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 7px; border-radius: 999px; min-width: 18px; text-align: center;
}

.cd-columns {
  display: grid; grid-template-columns: 1fr 1.85fr; gap: 20px;
  align-items: start;
}

/* Dark section header bars — Syncro style */
.cd-section { margin-bottom: 16px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); background: var(--white); }
.cd-section-head {
  background: #1e293b; color: #fff; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
}
.cd-section-head .cd-icon { margin-right: 8px; opacity: .7; }
.cd-section-head-title { display: flex; align-items: center; gap: 6px; }
.cd-section-head-actions { display: flex; gap: 6px; }

.cd-btn-new {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.2);
  padding: 3px 10px; border-radius: 4px; font-size: 11px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: background .15s;
}
.cd-btn-new:hover { background: rgba(255,255,255,.25); }

.cd-btn-viewall {
  display: inline-flex; align-items: center;
  background: var(--white); color: var(--text); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 4px; font-size: 11px; font-weight: 600;
  cursor: pointer; font-family: inherit; text-decoration: none; transition: background .15s;
}
.cd-btn-viewall:hover { background: var(--bg); }

.cd-section-body { padding: 0; }
.cd-section-body.padded { padding: 14px 16px; }

/* Compact table for client detail */
.cd-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cd-table th {
  padding: 8px 12px; text-align: left; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.cd-table td {
  padding: 9px 12px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle;
}
.cd-table tr:last-child td { border-bottom: none; }
.cd-table tr:hover td { background: #f8fafc; }
.cd-table a { color: var(--blue); text-decoration: none; font-weight: 600; }
.cd-table a:hover { text-decoration: underline; }

/* Overview card key-value rows */
.cd-kv { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.cd-kv:last-child { border-bottom: none; }
.cd-kv-label { color: var(--muted); font-weight: 600; }
.cd-kv-value { font-weight: 700; color: var(--text); }

.cd-kv-group-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 12px 16px 4px; }

/* Info rows with icons */
.cd-info-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 16px; font-size: 13px; }
.cd-info-row svg { width: 15px; height: 15px; fill: var(--muted); flex-shrink: 0; margin-top: 2px; }
.cd-info-label { color: var(--muted); min-width: 100px; font-weight: 500; }
.cd-info-value { color: var(--text); }
.cd-info-value a { color: var(--blue); text-decoration: none; }
.cd-info-value a:hover { text-decoration: underline; }

/* Notes textarea */
.cd-notes-area {
  width: 100%; min-height: 80px; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: 4px; font-size: 13px; font-family: inherit; color: var(--muted);
  resize: vertical; background: var(--bg); margin: 12px 16px; box-sizing: border-box;
  width: calc(100% - 32px);
}

/* Attachment items */
.cd-attachment {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.cd-attachment:last-child { border-bottom: none; }
.cd-attachment-icon {
  width: 36px; height: 36px; border-radius: 4px; background: var(--blue-bg);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  font-size: 11px; font-weight: 700; color: var(--blue);
}
.cd-attachment-name { font-weight: 600; color: var(--text); }
.cd-attachment-date { font-size: 11px; color: var(--muted); }
.cd-attachment-menu { margin-left: auto; color: var(--muted); cursor: pointer; font-size: 16px; }

/* Portal user pills */
.cd-user-pill {
  display: inline-block; background: var(--bg); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 4px; font-size: 12px; font-weight: 600; color: var(--text);
}
.cd-user-email {
  display: inline-block; background: var(--bg); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 4px; font-size: 12px; color: var(--muted);
}

/* Asset status dot */
.cd-status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px; }
.cd-status-dot.online { background: var(--green); }
.cd-status-dot.offline { background: var(--muted); }

/* Remote icons */
.cd-remote-icons { display: flex; gap: 4px; }
.cd-remote-icon {
  width: 26px; height: 26px; border-radius: 4px; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); cursor: pointer;
}
.cd-remote-icon svg { width: 14px; height: 14px; fill: var(--muted); }

/* Additional tickets link */
.cd-more-link { text-align: center; padding: 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.cd-more-link a { color: var(--blue); text-decoration: none; font-weight: 600; }

/* Tags select */
.cd-tags-select {
  width: 100%; padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 4px; font-size: 12px; color: var(--muted); background: var(--bg);
  font-family: inherit; cursor: pointer;
}

/* Dropdown button (Actions) */
.cd-dropdown { position: relative; display: inline-block; }
.cd-dropdown-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 7px 14px; background: var(--white); color: var(--text);
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.cd-dropdown-btn:hover { background: var(--bg); }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
  .portal-sidebar { transform: translateX(-100%); }
  .portal-sidebar.open { transform: translateX(0); }
  .portal-main { margin-left: 0; }
  .portal-menu-btn { display: block; }
  .portal-content { padding: 20px 16px; }
  .portal-form-row { grid-template-columns: 1fr; }
  .portal-topbar { padding: 0 16px; }
  .cd-columns { grid-template-columns: 1fr; }
  .cd-tabs { gap: 0; }
  .cd-tab { padding: 10px 12px; font-size: 12px; }
}

@media (max-width: 480px) {
  .portal-stats { grid-template-columns: 1fr 1fr; }
  .portal-table th:nth-child(n+4),
  .portal-table td:nth-child(n+4) { display: none; }
}
