/* ══════════════════════════════════════════════════════════════
   Saddah Command Center — Full Redesign
   Brand: Maestro Pizza / Saddah
   ══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@300;400;500;600;700&display=swap');

/* ── Variables ──────────────────────────────────────────────── */
:root {
  --primary:    #005142;
  --accent:     #00BE46;
  --gold:       #FFC000;
  --red:        #e43c2f;
  --bg:         #FCFCF0;
  --light-green:#ECF3E6;
  --border:     #e0e9e6;
  --muted:      #676767;
  --white:      #ffffff;
  --sidebar-w:  240px;
  --nav-h:      0px;
  --radius:     12px;
  --shadow:     0 2px 12px rgba(0,81,66,.10);
}

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

html, body {
  height: 100%;
  font-family: 'Rubik', sans-serif;
  background: var(--bg);
  color: #1a2e2a;
  font-size: 15px;
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; }
button { cursor: pointer; font-family: inherit; }

/* ── Layout ─────────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: var(--white);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
  position: relative;
  z-index: 100;
}

.sidebar-brand {
  padding: 28px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand .brand-icon {
  font-size: 28px;
  line-height: 1;
}

.sidebar-brand .brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.sidebar-brand .brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--white);
}

.sidebar-brand .brand-sub {
  font-size: 10px;
  font-weight: 400;
  color: rgba(255,255,255,.55);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: rgba(255,255,255,.75);
  transition: all .18s ease;
}

.nav-item:hover {
  background: rgba(255,255,255,.10);
  color: var(--white);
}

.nav-item.active {
  background: rgba(255,255,255,.15);
  color: var(--white);
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-item .nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid rgba(255,255,255,.12);
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(228,60,47,.15);
  color: rgba(255,255,255,.8);
  border: none;
  width: 100%;
  font-size: 14px;
  font-weight: 500;
  transition: all .18s;
}

.logout-btn:hover {
  background: rgba(228,60,47,.35);
  color: var(--white);
}

/* ── Main Content ─────────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Page Header ─────────────────────────────────────────────── */
.page-header {
  padding: 24px 32px 0;
  flex-shrink: 0;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}

.page-subtitle {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

/* ══════════════════════════════════════════════════════════════
   DASHBOARDS PAGE
   ══════════════════════════════════════════════════════════════ */

.dashboards-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dash-tabs {
  display: flex;
  gap: 4px;
  padding: 16px 24px 0;
  background: var(--white);
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}

.dash-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 10px 10px 0 0;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-bottom: none;
  background: var(--white);
  color: var(--primary);
  cursor: pointer;
  transition: all .18s;
  position: relative;
  bottom: -2px;
}

.dash-tab:hover {
  background: var(--light-green);
}

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

.dash-tab .tab-icon {
  font-size: 16px;
}

.iframe-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.dash-panel {
  display: none;
  height: 100%;
  flex-direction: column;
}

.dash-panel.active {
  display: flex;
}

.iframe-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: var(--light-green);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.iframe-url {
  font-size: 12px;
  color: var(--muted);
  font-family: monospace;
}

.open-new-tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--white);
  border: none;
  font-size: 12px;
  font-weight: 500;
  transition: background .18s;
}

.open-new-tab-btn:hover {
  background: #006b57;
}

.iframe-wrapper {
  flex: 1;
  position: relative;
}

.iframe-wrapper iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.iframe-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  gap: 12px;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s;
}

.iframe-placeholder.visible {
  opacity: 1;
  pointer-events: auto;
}

.iframe-placeholder .placeholder-icon {
  font-size: 48px;
}

.iframe-placeholder p {
  font-size: 15px;
  color: var(--muted);
  font-weight: 500;
}

.iframe-placeholder small {
  font-size: 12px;
  color: #aaa;
}

/* ══════════════════════════════════════════════════════════════
   AGENTS PAGE
   ══════════════════════════════════════════════════════════════ */

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

.agents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin-top: 24px;
}

.agent-card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  box-shadow: var(--shadow);
  transition: transform .2s, box-shadow .2s;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.agent-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0,81,66,.14);
}

.agent-card-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.agent-avatar {
  width: 60px;
  height: 60px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: visible;
}

.agent-avatar svg {
  width: 60px;
  height: 60px;
}

.agent-header-info {
  flex: 1;
  min-width: 0;
}

.agent-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.agent-role-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: var(--light-green);
  color: var(--primary);
  border: 1px solid var(--border);
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
}

.status-dot::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(0,190,70,.2);
}

.agent-description {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}

.agent-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meta-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
}

.meta-label {
  font-weight: 600;
  color: var(--primary);
  min-width: 80px;
  flex-shrink: 0;
  padding-top: 1px;
}

.meta-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.meta-tag {
  padding: 1px 8px;
  border-radius: 6px;
  background: #f0f4f3;
  color: #3a5a52;
  font-size: 11px;
  border: 1px solid var(--border);
}

.freq-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--gold) 0%, #ffad00 100%);
  color: #5a3d00;
  font-size: 11px;
  font-weight: 600;
}

.agent-card-footer {
  margin-top: auto;
  display: flex;
  justify-content: flex-end;
}

.view-details-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 8px;
  background: var(--light-green);
  border: 1px solid var(--border);
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  transition: all .18s;
}

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

/* ── Agent Modal ──────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--white);
  border-radius: 16px;
  width: 90%;
  max-width: 620px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px 28px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header .agent-avatar {
  width: 72px;
  height: 72px;
}

.modal-header .agent-avatar svg {
  width: 72px;
  height: 72px;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

.modal-subtitle {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
}

.modal-close {
  margin-left: auto;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #f0f0f0;
  border: none;
  font-size: 18px;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}

.modal-close:hover {
  background: #e0e0e0;
}

.modal-body {
  padding: 24px 28px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 8px;
}

.modal-tasks {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-task-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: #2a3a36;
}

.modal-task-item::before {
  content: '→';
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
  line-height: 1.6;
}

/* ══════════════════════════════════════════════════════════════
   LOGICS PAGE
   ══════════════════════════════════════════════════════════════ */

.logics-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.logics-tabs {
  display: flex;
  gap: 4px;
  padding: 20px 32px 0;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.logic-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 10px 10px 0 0;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-bottom: none;
  background: var(--white);
  color: var(--primary);
  cursor: pointer;
  transition: all .18s;
  position: relative;
  bottom: -2px;
}

.logic-tab:hover { background: var(--light-green); }

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

.logics-panels {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.logic-panel {
  display: none;
}

.logic-panel.active {
  display: block;
}

.logic-panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.logic-panel-avatar {
  width: 48px;
  height: 48px;
}

.logic-panel-avatar svg {
  width: 48px;
  height: 48px;
}

.logic-panel-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.logic-panel-role {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.mermaid-wrapper {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 32px;
  box-shadow: var(--shadow);
  overflow-x: auto;
  display: flex;
  justify-content: center;
}

.mermaid-wrapper .mermaid {
  max-width: 100%;
}

/* ══════════════════════════════════════════════════════════════
   LOGIN PAGE
   ══════════════════════════════════════════════════════════════ */

.login-page {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--white);
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0,81,66,.12);
  overflow: hidden;
}

.login-header {
  background: var(--primary);
  padding: 36px 32px 28px;
  text-align: center;
  color: var(--white);
}

.login-logo {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 8px;
}

.login-brand {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--white);
}

.login-tagline {
  font-size: 12px;
  color: rgba(255,255,255,.6);
  margin-top: 4px;
  letter-spacing: 1px;
}

.login-body {
  padding: 32px;
}

.login-form-group {
  margin-bottom: 18px;
}

.login-form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  margin-bottom: 6px;
}

.login-form-group input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  font-family: 'Rubik', sans-serif;
  font-size: 14px;
  color: #1a2e2a;
  outline: none;
  transition: border-color .18s;
}

.login-form-group input:focus {
  border-color: var(--primary);
}

.login-submit {
  width: 100%;
  padding: 13px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: var(--white);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .5px;
  margin-top: 8px;
  transition: background .18s;
}

.login-submit:hover { background: #006b57; }

.login-error {
  background: #fdf0ef;
  border: 1px solid #f5c6c2;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--red);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.login-footer {
  text-align: center;
  padding: 0 32px 24px;
  font-size: 11px;
  color: var(--muted);
}

/* ══════════════════════════════════════════════════════════════
   SCROLLBAR STYLING
   ══════════════════════════════════════════════════════════════ */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #bfd0cb; }

/* ── Flash messages ───────────────────────────────────────────── */
.flash-messages {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flash-msg {
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  background: var(--white);
  border-left: 4px solid var(--accent);
  color: #1a2e2a;
}

.flash-msg.warning { border-left-color: var(--gold); }
.flash-msg.error   { border-left-color: var(--red); }
