/* iRest /master — área de gestão da plataforma (Platform Admins).
 * Paleta de "comando": tons mais escuros do range (deep purple/blue) para
 * distinguir visualmente de /app e /admin de tenant.
 */

:root {
    --p1: #FFC107;
    --p2: #FF5722;
    --p3: #D81B60;
    --p4: #7B1FA2;
    --p5: #491D8B;
    --p6: #001D6C;

    --ms-primary:      var(--p6);
    --ms-primary-dark: #00104a;
    --ms-accent:       var(--p2);
    --ms-bg:           #F1F2F8;
    --ms-surface:      #ffffff;
    --ms-text:         #0A1239;
    --ms-muted:        #5B617C;
    --ms-border:       #DDE0EA;

    --ms-gradient-cmd:   linear-gradient(135deg, var(--p5), var(--p6));  /* purple→blue */
    --ms-gradient-deep:  linear-gradient(135deg, var(--p6), #000928);
    --ms-gradient-warm:  linear-gradient(135deg, var(--p1), var(--p2));

    --radius-card: 20px;
    --radius-pill: 999px;
    --radius-input: 14px;
}

html, body { height: 100%; }
body.ms-body {
    background: var(--ms-bg);
    color: var(--ms-text);
    font-family: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
body.ms-body a, body.ms-body a:hover, body.ms-body a:focus { text-decoration: none; color: inherit; }
h1, h2, h3, h4, h5, h6 { font-family: 'Lato', sans-serif; font-weight: 700; }
.font-display { font-family: 'Roboto Slab', Georgia, serif; }

/* Layout shell */
.ms-layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100dvh; }
@media (max-width: 767.98px) { .ms-layout { grid-template-columns: 1fr; } }

.ms-sidebar {
    background: var(--ms-gradient-deep);
    color: #d6d8eb;
    padding: 18px 14px;
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100dvh; overflow-y: auto;
}
.ms-sidebar-brand {
    display: flex; align-items: center; gap: 12px;
    padding: 6px 8px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.10);
    margin-bottom: 14px;
}
.ms-sidebar-brand .mark {
    width: 42px; height: 42px; border-radius: 12px;
    background: var(--ms-gradient-warm);
    display: inline-flex; align-items: center; justify-content: center; color: #fff;
    font-size: 1.3rem;
    box-shadow: 0 8px 20px rgba(255, 87, 34, 0.30);
}
.ms-sidebar-brand .name {
    font-family: 'Roboto Slab', Georgia, serif;
    font-weight: 700; font-size: 1.15rem;
}
.ms-sidebar-brand .who { font-size: 0.78rem; opacity: 0.72; }

.ms-nav { list-style: none; padding: 0; margin: 0; flex: 1; }
.ms-nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: var(--radius-pill);
    color: #c5c8df; font-size: 0.95rem; font-weight: 500;
    margin-bottom: 2px;
}
.ms-nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.ms-nav-item.active { background: rgba(255,255,255,0.16); color: #fff; font-weight: 700; }
.ms-nav-item i { font-size: 1.1rem; min-width: 18px; text-align: center; }

.ms-sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.10);
    padding-top: 10px;
    font-size: 0.85rem;
}
.ms-sidebar-footer .logout-btn {
    background: transparent; border: 0; color: var(--p1); font-weight: 600;
    padding: 4px 0; cursor: pointer;
}
.ms-sidebar-footer .logout-btn:hover { color: #fff; }

.ms-topbar { display: none; }
@media (max-width: 767.98px) {
    .ms-layout > .ms-sidebar { display: none; }
    .ms-layout.with-mobile-nav > .ms-sidebar {
        display: flex; position: fixed; left: 0; top: 0; bottom: 0;
        width: 288px; z-index: 1040; box-shadow: 0 0 40px rgba(0,0,0,0.4);
    }
    .ms-topbar {
        display: flex; align-items: center; justify-content: space-between;
        background: var(--ms-gradient-deep); color: #fff; padding: 12px 16px;
        position: sticky; top: 0; z-index: 1030;
    }
    .ms-topbar .menu-btn { background: transparent; border: 0; color: #fff; font-size: 1.4rem; }
}

.ms-content {
    padding: 24px 28px 36px;
    max-width: 1400px; margin: 0 auto; width: 100%;
}
@media (max-width: 767.98px) { .ms-content { padding: 16px; } }

.ms-page-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin-bottom: 20px; flex-wrap: wrap;
}
.ms-page-head h1 {
    font-family: 'Roboto Slab', Georgia, serif;
    font-size: 1.6rem; font-weight: 700; margin: 0;
}
.ms-page-head .subtitle { color: var(--ms-muted); font-size: 0.92rem; }

/* Cards / cards de tenant */
.ms-card {
    background: var(--ms-surface);
    border: 1px solid var(--ms-border);
    border-radius: var(--radius-card);
    padding: 18px;
    margin-bottom: 16px;
}

.tenant-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 14px;
}
.tenant-card {
    background: #fff;
    border: 1px solid var(--ms-border);
    border-radius: var(--radius-card);
    overflow: hidden;
    position: relative;
    display: flex; flex-direction: column;
    transition: box-shadow .18s ease, transform .18s ease;
    cursor: pointer;
}
.tenant-card:hover { box-shadow: 0 12px 28px rgba(0, 29, 108, 0.10); transform: translateY(-1px); }
.tenant-card.suspended { opacity: 0.7; }
.tenant-card .brand-band {
    height: 8px; display: flex;
}
.tenant-card .brand-band span { flex: 1; }
.tenant-card .body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 8px; }
.tenant-card .head { display: flex; align-items: center; justify-content: space-between; }
.tenant-card .name {
    font-family: 'Roboto Slab', Georgia, serif;
    font-size: 1.2rem; font-weight: 700;
    color: var(--ms-text);
}
.tenant-card .code {
    font-family: 'Roboto Slab', Georgia, serif;
    font-size: 0.85rem; color: var(--ms-muted);
}
.tenant-card .meta {
    display: flex; gap: 14px; font-size: 0.85rem; color: var(--ms-muted);
    margin-top: 6px;
}
.tenant-card .meta b { color: var(--ms-text); font-weight: 700; font-variant-numeric: tabular-nums; }

/* Status pills */
.status-pill {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: var(--radius-pill);
    font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
}
.status-pill.active    { background: #FFF3E0; color: #B25400; }
.status-pill.suspended { background: #FDE7EE; color: var(--p3); }
.status-pill.deleted   { background: #EAEAF0; color: #4A4459; }

/* Logo upload */
.logo-row {
    display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
    padding: 14px; border: 1px solid var(--ms-border); border-radius: 14px;
    background: #FAFAFC;
}
.logo-preview {
    width: 120px; height: 120px;
    border: 1px dashed var(--ms-border);
    border-radius: 14px;
    background: #fff;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
    flex: 0 0 auto;
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-preview i  { font-size: 2.4rem; opacity: 0.4; }
.logo-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Brand editor: 6 cores ordenadas */
.brand-swatch-row { display: flex; gap: 10px; flex-wrap: wrap; }
.brand-swatch {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    flex: 1 1 100px; min-width: 100px;
}
.brand-swatch .swatch-color {
    width: 100%; height: 56px; border-radius: 14px;
    border: 1px solid var(--ms-border);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.brand-swatch .swatch-color input[type="color"] {
    position: absolute; inset: 0; width: 100%; height: 100%; border: 0; padding: 0;
    background: transparent; opacity: 0; cursor: pointer;
}
.brand-swatch .swatch-label { font-size: 0.72rem; color: var(--ms-muted); }
.brand-swatch .swatch-hex {
    font-family: 'Roboto Slab', monospace; font-size: 0.78rem; font-weight: 600;
    border: 1px solid var(--ms-border); border-radius: 6px;
    padding: 2px 6px; text-align: center; width: 80px;
    text-transform: uppercase;
}
.brand-preview {
    height: 20px; border-radius: var(--radius-pill);
    background: linear-gradient(90deg, var(--bc1), var(--bc2), var(--bc3), var(--bc4), var(--bc5), var(--bc6));
    margin-top: 12px;
}

/* Login screen */
.ms-login {
    min-height: 100dvh;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    background:
        radial-gradient(circle at 80% 0%, rgba(73, 29, 139, 0.15), transparent 40%),
        radial-gradient(circle at 20% 100%, rgba(0, 29, 108, 0.18), transparent 40%),
        var(--ms-bg);
}
.ms-login .card {
    background: #fff; border-radius: var(--radius-card);
    border: 1px solid var(--ms-border);
    box-shadow: 0 24px 60px rgba(0, 29, 108, 0.10);
    padding: 32px; max-width: 420px; width: 100%;
}
.ms-login .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.ms-login .brand .mark {
    width: 48px; height: 48px; border-radius: 14px;
    background: var(--ms-gradient-warm);
    display: inline-flex; align-items: center; justify-content: center; color: #fff;
    font-size: 1.5rem;
}
.ms-login .brand .name {
    font-family: 'Roboto Slab', Georgia, serif;
    font-weight: 700; font-size: 1.35rem;
}
.ms-login .brand .sub { font-size: 0.8rem; color: var(--ms-muted); }

/* Forms / buttons */
.btn { font-family: inherit; font-weight: 600; border-radius: var(--radius-pill); }
.btn-primary {
    --bs-btn-bg: var(--ms-primary);
    --bs-btn-border-color: var(--ms-primary);
    --bs-btn-hover-bg: var(--ms-primary-dark);
    --bs-btn-hover-border-color: var(--ms-primary-dark);
    --bs-btn-active-bg: var(--ms-primary-dark);
    --bs-btn-active-border-color: var(--ms-primary-dark);
}
.btn-grad {
    background: var(--ms-gradient-cmd); color: #fff; border: 0;
    padding: 8px 18px; border-radius: var(--radius-pill); font-weight: 700;
    box-shadow: 0 6px 16px rgba(73, 29, 139, 0.25);
}
.btn-grad:hover { filter: brightness(1.06); color: #fff; }
.form-control, .form-select { border-radius: var(--radius-input); }
.form-control:focus, .form-select:focus {
    border-color: var(--p4);
    box-shadow: 0 0 0 0.25rem rgba(123, 31, 162, 0.15);
}

/* Empty / loading / spinner */
.ms-empty { text-align: center; padding: 48px 16px; color: var(--ms-muted); }
.ms-empty i { display: block; font-size: 2.8rem; opacity: 0.5; margin-bottom: 10px; color: var(--p4); }
.ms-spinner-overlay {
    position: fixed; inset: 0; background: rgba(241, 242, 248, 0.6);
    backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center; z-index: 1050;
}
.ms-spinner-overlay .spinner-border { color: var(--p4) !important; }

/* Toast */
.ms-toast-area {
    position: fixed; right: 18px; bottom: 18px;
    z-index: 1100; display: flex; flex-direction: column; gap: 10px; max-width: 380px;
    pointer-events: none;
}
.ms-toast {
    background: var(--ms-text); color: #fff;
    padding: 13px 16px; border-radius: var(--radius-input);
    box-shadow: 0 14px 30px rgba(0, 29, 108, 0.18);
    opacity: 0; transform: translateY(8px);
    transition: opacity .18s ease, transform .18s ease;
    font-size: 0.9rem; font-weight: 600;
}
.ms-toast.show { opacity: 1; transform: translateY(0); }
.ms-toast.error   { background: var(--p3); }
.ms-toast.success { background: var(--p2); }

/* Modal */
.modal-content { border-radius: var(--radius-card); border: 1px solid var(--ms-border); }
.modal-title { font-family: 'Roboto Slab', Georgia, serif; font-weight: 700; }

/* KPI grid */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi {
    background: #fff; border: 1px solid var(--ms-border); border-radius: var(--radius-card);
    padding: 16px 18px;
}
.kpi .label { color: var(--ms-muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.kpi .value {
    font-size: 1.8rem; font-weight: 700; margin-top: 4px;
    font-family: 'Roboto Slab', Georgia, serif;
}

/* Card head com botão de acção */
.ms-card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 14px;
}
.ms-card-head h6 { font-size: 1rem; }

/* Tabelas dentro de ms-card */
.ms-table {
    width: 100%; border-collapse: collapse; font-size: 0.9rem;
}
.ms-table thead th {
    text-align: left; font-weight: 700; font-size: 0.74rem;
    text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--ms-muted); padding: 8px 10px;
    border-bottom: 1px solid var(--ms-border);
}
.ms-table tbody td {
    padding: 10px; border-bottom: 1px solid #F2F2F6; vertical-align: middle;
}
.ms-table tbody tr:last-child td { border-bottom: none; }
.ms-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.ms-table .actions { text-align: right; white-space: nowrap; }
.ms-table code {
    background: #F5F5F8; padding: 1px 6px; border-radius: 6px;
    font-size: 0.82rem; color: var(--p5);
}

/* Pill de papel (Admin / SuperAdmin) */
.role-pill {
    display: inline-block; padding: 2px 10px;
    border-radius: 999px; font-size: 0.74rem; font-weight: 700;
    background: #EEF0F6; color: var(--ms-muted);
    text-transform: uppercase; letter-spacing: 0.04em;
}
.role-pill.super { background: var(--p5); color: #fff; }

/* Tenant card variantes de estado */
.tenant-card.deleted { opacity: 0.65; }
.tenant-card.deleted::after {
    content: 'OFFBOARDED'; position: absolute; top: 12px; right: 12px;
    background: var(--ms-muted); color: #fff;
    padding: 2px 10px; border-radius: 999px;
    font-size: 0.66rem; font-weight: 800; letter-spacing: 0.08em;
}

/* Banner de offboard no TenantDetail */
.offboard-banner {
    background: #FFF5DD;
    border: 1px solid #F0C25F;
    border-left: 4px solid #C58300;
    border-radius: var(--radius-card);
    padding: 14px 18px;
    margin-bottom: 18px;
    color: #5A3A00;
}
.offboard-banner strong {
    display: block; font-family: 'Roboto Slab', Georgia, serif;
    font-size: 1.02rem; margin-bottom: 4px;
}
.offboard-banner .badge { font-weight: 600; }
.offboard-banner code { background: rgba(0,0,0,0.06); padding: 1px 6px; border-radius: 4px; }

/* SMS log */
.sms-log-toolbar {
    display: flex; align-items: center; gap: 16px;
    margin: -6px 0 14px; flex-wrap: wrap;
}
.sms-log-list { width: 100%; max-height: calc(100vh - 280px); overflow-y: auto; }
.sms-log-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.sms-log-table thead th {
    text-align: left; font-weight: 700; font-size: 0.72rem;
    text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--ms-muted);
    padding: 10px 14px; background: #FAFAFC;
    border-bottom: 1px solid var(--ms-border);
    position: sticky; top: 0; z-index: 1;
}
.sms-log-table tbody td {
    padding: 9px 14px; border-bottom: 1px solid #F2F2F6; vertical-align: top;
}
.sms-log-table tbody tr:last-child td { border-bottom: none; }
.sms-log-table tbody tr:hover { background: #FAFAFC; }
.sms-log-table .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.82rem; white-space: nowrap; color: #4A4459;
}
.sms-log-table .msg { color: #1A1A1F; }
.sms-log-table .msg code.otp {
    background: #FFF3E0; color: #B25400; font-weight: 700;
    padding: 1px 8px; border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.88rem;
}
.sms-log-empty { padding: 28px; text-align: center; color: var(--ms-muted); }

/* Onboarding wizard */
.ms-wizard-stepper {
    display: flex; align-items: center; justify-content: center;
    gap: 8px; margin: 4px 0 22px;
}
.ms-wizard-dot {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 12px 6px 6px;
    border-radius: 999px;
    background: #F1F1F6;
    color: var(--ms-muted);
    font-size: 0.85rem; font-weight: 600;
    transition: background 0.18s, color 0.18s;
}
.ms-wizard-dot .num {
    width: 24px; height: 24px; border-radius: 50%;
    background: #fff; border: 1px solid var(--ms-border);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.8rem;
}
.ms-wizard-dot.active {
    background: var(--p5); color: #fff;
}
.ms-wizard-dot.active .num { background: rgba(255,255,255,0.18); border-color: transparent; color: #fff; }
.ms-wizard-dot.done {
    background: var(--p2); color: #fff;
}
.ms-wizard-dot.done .num { background: rgba(255,255,255,0.22); border-color: transparent; color: #fff; }
.ms-wizard-line {
    flex: 0 0 28px; height: 2px; background: var(--ms-border); border-radius: 2px;
}
.ms-wizard-step { padding-top: 4px; }
.ms-wizard-step .brand-swatch-row { margin-bottom: 14px; }
.ms-wizard-step .brand-preview { margin-bottom: 0; }
@media (max-width: 540px) {
    .ms-wizard-dot .label { display: none; }
}
