/* ============================================================
   mytools-core admin UI
   Design: clean, dense, utilitarian. Optimized for long sessions
   of tenant/subscription management.
   ============================================================ */

:root {
    --color-bg:        #f4f5f7;
    --color-card:      #ffffff;
    --color-text:      #0f172a;
    --color-muted:     #64748b;
    --color-border:    #e2e8f0;
    --color-primary:   #1e40af;
    --color-primary-hover: #1d4ed8;
    --color-primary-contrast: #ffffff;
    --color-danger:    #dc2626;
    --color-warn:      #d97706;
    --color-ok:        #15803d;

    --sidebar-w:  240px;
    --radius:     8px;
    --radius-sm:  4px;

    --font-body:    system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono:    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

    --shadow-sm:  0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md:  0 4px 12px rgba(15, 23, 42, 0.08);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; }
body, h1, h2, h3, h4, p, dl, dd, dt, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

html, body {
    font-family: var(--font-body);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.5;
    font-size: 15px;
}

code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    background: #eef1f5;
    padding: 1px 5px;
    border-radius: 3px;
    color: #334155;
}

/* ============================================================
   App layout — sidebar + main
   ============================================================ */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}
.app--public {
    display: block;
    background: #e2e8f0;
}

/* ---- Sidebar ---- */
.sidebar {
    background: #0f172a;
    color: #cbd5e1;
    padding: 1.25rem 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar__brand {
    padding: 0 1.25rem 1.5rem;
    border-bottom: 1px solid #1e293b;
}
.sidebar__brand strong {
    color: #fff;
    font-size: 1.1rem;
    display: block;
}
.sidebar__brand small {
    color: #64748b;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.sidebar__nav {
    display: flex;
    flex-direction: column;
    padding: 0.75rem 0.75rem;
    flex: 1;
}
.sidebar__nav a {
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    font-size: 0.92rem;
    color: #94a3b8;
    transition: background 0.1s, color 0.1s;
}
.sidebar__nav a:hover {
    background: #1e293b;
    color: #fff;
}
.sidebar__nav a.is-active {
    background: #1e293b;
    color: #fff;
    font-weight: 600;
}
.sidebar__footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid #1e293b;
    font-size: 0.82rem;
}
.sidebar__user span {
    display: block;
    color: #fff;
    font-weight: 500;
}
.sidebar__user small {
    color: #64748b;
    font-size: 0.78rem;
}
.sidebar__logout {
    margin-top: 0.75rem;
}
.sidebar__logout button {
    background: transparent;
    border: 1px solid #334155;
    color: #94a3b8;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    width: 100%;
}
.sidebar__logout button:hover {
    border-color: #64748b;
    color: #fff;
}

/* ---- Main ---- */
.main {
    padding: 2rem 2.5rem;
    min-width: 0;
}

/* ============================================================
   Page headers, breadcrumbs
   ============================================================ */
.page__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.75rem;
    flex-wrap: wrap;
}
.page__header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}
.page__subtitle {
    color: var(--color-muted);
    font-size: 0.92rem;
    margin-top: 0.2rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.breadcrumb {
    font-size: 0.85rem;
    color: var(--color-muted);
    margin-bottom: 0.4rem;
}
.breadcrumb a {
    color: var(--color-muted);
}
.breadcrumb a:hover {
    color: var(--color-text);
}

/* ============================================================
   Cards
   ============================================================ */
.card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    overflow: hidden;
}
.card__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
}
.card__header h2 {
    font-size: 1rem;
    font-weight: 600;
}

/* ============================================================
   Stats grid
   ============================================================ */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.08s, box-shadow 0.08s;
    display: block;
}
a.stat:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    border-color: #cbd5e1;
}
.stat__value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.1;
    margin-bottom: 0.25rem;
}
.stat__label {
    color: var(--color-muted);
    font-size: 0.85rem;
}
.stat--ok   .stat__value { color: var(--color-ok); }
.stat--warn .stat__value { color: var(--color-warn); }

/* ============================================================
   Tables
   ============================================================ */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
.table th {
    text-align: left;
    padding: 0.7rem 1.25rem;
    background: #f8fafc;
    color: var(--color-muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--color-border);
}
.table td {
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover {
    background: #f8fafc;
}
.table--clickable tbody tr {
    cursor: pointer;
}
.table__actions {
    text-align: right;
}
.table a {
    color: var(--color-primary);
    font-weight: 500;
}
.table a:hover { text-decoration: underline; }

/* ============================================================
   Toolbar (filter/search row)
   ============================================================ */
.toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.toolbar input[type="text"] {
    flex: 1;
    padding: 0.5rem 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
}
.toolbar select {
    padding: 0.5rem 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
}

/* ============================================================
   Forms
   ============================================================ */
.form {
    padding: 1.5rem;
}
.form--wide {
    max-width: 820px;
}
.form__row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.form__actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--color-border);
}
.field {
    display: block;
    margin-bottom: 1rem;
}
.field--narrow {
    max-width: 180px;
}
.field--checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.field__label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 0.35rem;
}
.field__hint {
    display: block;
    color: var(--color-muted);
    font-size: 0.8rem;
    margin-top: 0.3rem;
}
.field input:not([type="checkbox"]):not([type="color"]),
.field select,
.field textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: 0;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.12);
}
.field textarea {
    resize: vertical;
    font-family: var(--font-body);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-block;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-weight: 500;
    font-size: 0.9rem;
    text-align: center;
    transition: background 0.1s, border-color 0.1s, transform 0.06s;
}
.btn:active { transform: translateY(1px); }
.btn--sm { padding: 0.3rem 0.75rem; font-size: 0.82rem; }
.btn--block { display: block; width: 100%; }
.btn--primary {
    background: var(--color-primary);
    color: var(--color-primary-contrast);
}
.btn--primary:hover {
    background: var(--color-primary-hover);
}
.btn--ghost {
    background: transparent;
    border-color: var(--color-border);
    color: var(--color-text);
}
.btn--ghost:hover {
    border-color: var(--color-muted);
    background: #fff;
}

/* ============================================================
   Badges (status pills)
   ============================================================ */
.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: #e2e8f0;
    color: #475569;
}
.badge--active,
.badge--trial              { background: #dcfce7; color: #166534; }
.badge--pending_activation { background: #fef9c3; color: #854d0e; }
.badge--past_due           { background: #fed7aa; color: #9a3412; }
.badge--suspended          { background: #fecaca; color: #991b1b; }
.badge--cancelled          { background: #e2e8f0; color: #475569; }

/* ============================================================
   Detail (dt/dd grid for show pages)
   ============================================================ */
.detail {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.25rem;
    padding: 1.5rem;
}
.detail > div dt {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.2rem;
}
.detail > div dd {
    font-size: 0.95rem;
    color: var(--color-text);
}
.notes {
    padding: 1rem 1.5rem 1.5rem;
    border-top: 1px solid var(--color-border);
    background: #f8fafc;
}
.notes h3 {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.5rem;
}
.notes p { color: var(--color-text); }

/* ============================================================
   Flash messages
   ============================================================ */
.flash {
    padding: 0.75rem 1.1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.92rem;
    border: 1px solid transparent;
}
.flash--success { background: #dcfce7; border-color: #bbf7d0; color: #166534; }
.flash--error   { background: #fee2e2; border-color: #fecaca; color: #991b1b; }
.flash--info    { background: #dbeafe; border-color: #bfdbfe; color: #1e40af; }

/* ============================================================
   Empty states
   ============================================================ */
.empty {
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--color-muted);
}
.empty p {
    margin-bottom: 1.25rem;
}

/* ============================================================
   Login card (public layout)
   ============================================================ */
.public-main {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}
.login-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2.25rem 2rem;
    width: 100%;
    max-width: 400px;
}
.login-card__head {
    text-align: center;
    margin-bottom: 1.75rem;
}
.login-card__head strong {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
}
.login-card__head small {
    color: var(--color-muted);
    font-size: 0.82rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 800px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: static;
        height: auto;
        flex-direction: row;
        align-items: center;
        padding: 0.75rem 1rem;
    }
    .sidebar__brand { border: 0; padding: 0 1rem 0 0; }
    .sidebar__nav { flex-direction: row; padding: 0; flex: 1; overflow-x: auto; }
    .sidebar__nav a { margin: 0 2px; white-space: nowrap; }
    .sidebar__footer { border: 0; padding: 0; }
    .sidebar__user { display: none; }
    .main { padding: 1.5rem 1rem; }
}
