/*
Theme Name: MedicalSpaces Management
Theme URI: https://medicalspaces.ch
Description: Standalone management portal for MedicalSpaces GmbH. Beautiful custom login, frontend CRUD for all entities, no WordPress admin bar. Requires the MedicalSpaces API plugin.
Version: 2.0.0
Author: MedicalSpaces GmbH
Author URI: https://medicalspaces.ch
Text Domain: medicalspaces-theme
Requires at least: 6.4
Requires PHP: 8.1
License: GPL-2.0+
*/

/* ========== Variables ========== */
:root {
    --primary: #1a3a2a;
    --primary-light: #2a5a40;
    --primary-dark: #0f2419;
    --accent: #6b8f71;
    --gold: #c4944a;
    --gold-light: #d4a55c;
    --cream: #f8f5f0;
    --bg: #f4f5f7;
    --card: #ffffff;
    --text: #1d2327;
    --text-light: #4b5563;
    --muted: #6b7280;
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --green: #059669;
    --green-light: #d1fae5;
    --red: #dc2626;
    --red-light: #fee2e2;
    --orange: #d97706;
    --orange-light: #fef3c7;
    --blue: #2563eb;
    --blue-light: #dbeafe;
    --purple: #7c3aed;
    --purple-light: #ede9fe;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.07), 0 4px 6px -2px rgba(0,0,0,0.03);
    --radius: 10px;
    --radius-lg: 14px;
    --radius-sm: 6px;
}

/* ========== Reset ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg); color: var(--text);
    -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
    line-height: 1.5;
}
a { color: var(--primary-light); text-decoration: none; }
a:hover { color: var(--gold); }
button, input, textarea, select { font-family: inherit; font-size: inherit; }
img { max-width: 100%; display: block; }

/* Hide WordPress admin bar completely */
html { margin-top: 0 !important; }
* html body { margin-top: 0 !important; }
#wpadminbar { display: none !important; }

/* ========== Login Screen ========== */
.ms-login-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--cream);
}

.ms-login-brand {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
    color: #fff;
    display: flex; flex-direction: column; justify-content: space-between;
    padding: 60px;
    position: relative;
    overflow: hidden;
}

.ms-login-brand::before {
    content: ''; position: absolute; inset: 0;
    background-image:
        radial-gradient(circle at 20% 80%, rgba(196, 148, 74, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 80% 20%, rgba(107, 143, 113, 0.2) 0%, transparent 40%);
}

.ms-login-brand-inner { position: relative; z-index: 1; }

.ms-login-logo {
    display: flex; align-items: center; gap: 14px; margin-bottom: 80px;
}
.ms-login-logo-mark {
    width: 56px; height: 56px;
    background: var(--gold);
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; color: var(--primary-dark); font-weight: 800;
    box-shadow: 0 8px 20px rgba(196, 148, 74, 0.4);
}
.ms-login-logo-text { font-family: 'Playfair Display', serif; font-size: 28px; font-weight: 700; }
.ms-login-logo-sub { font-size: 11px; letter-spacing: 3px; text-transform: uppercase; color: rgba(255,255,255,0.6); margin-top: 4px; }

.ms-login-tagline {
    font-family: 'Playfair Display', serif; font-size: 48px; font-weight: 700;
    line-height: 1.1; margin-bottom: 24px; color: #fff;
}
.ms-login-tagline span { color: var(--gold); font-style: italic; }

.ms-login-features {
    list-style: none; display: flex; flex-direction: column; gap: 14px; margin-top: 36px;
}
.ms-login-features li {
    display: flex; align-items: center; gap: 12px;
    font-size: 15px; color: rgba(255,255,255,0.85);
}
.ms-login-features svg { width: 20px; height: 20px; color: var(--gold); flex-shrink: 0; }

.ms-login-footer {
    position: relative; z-index: 1;
    font-size: 13px; color: rgba(255,255,255,0.5);
    display: flex; justify-content: space-between; align-items: center;
}
.ms-login-footer a { color: rgba(255,255,255,0.7); }

.ms-login-form-wrap {
    display: flex; align-items: center; justify-content: center;
    padding: 60px 40px;
}
.ms-login-form {
    width: 100%; max-width: 400px;
}
.ms-login-form h1 {
    font-family: 'Playfair Display', serif; font-size: 36px; font-weight: 700;
    color: var(--primary); margin-bottom: 8px;
}
.ms-login-form p.subtitle {
    color: var(--muted); margin-bottom: 36px; font-size: 15px;
}

.ms-form-group { margin-bottom: 20px; }
.ms-form-group label {
    display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; color: var(--text);
}
.ms-form-group input, .ms-form-group textarea, .ms-form-group select {
    width: 100%; padding: 12px 16px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--card); font-size: 15px; color: var(--text);
    transition: all 0.2s;
}
.ms-form-group input:focus, .ms-form-group textarea:focus, .ms-form-group select:focus {
    outline: none; border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(42, 90, 64, 0.1);
}
.ms-form-group input[type="checkbox"] { width: auto; margin-right: 8px; }

.ms-login-error {
    padding: 12px 16px; background: var(--red-light); color: var(--red);
    border-radius: var(--radius); font-size: 14px; margin-bottom: 20px;
    border-left: 3px solid var(--red);
}
.ms-login-success {
    padding: 12px 16px; background: var(--green-light); color: var(--green);
    border-radius: var(--radius); font-size: 14px; margin-bottom: 20px;
}

.ms-btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px; padding: 12px 20px;
    border: none; border-radius: var(--radius); cursor: pointer;
    font-size: 14px; font-weight: 600; transition: all 0.15s;
    text-decoration: none; line-height: 1;
}
.ms-btn-primary { background: var(--primary); color: #fff; }
.ms-btn-primary:hover { background: var(--primary-light); color: #fff; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.ms-btn-gold { background: var(--gold); color: #fff; }
.ms-btn-gold:hover { background: var(--gold-light); color: #fff; }
.ms-btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.ms-btn-outline:hover { background: var(--bg); color: var(--text); }
.ms-btn-danger { background: transparent; color: var(--red); border: 1px solid var(--red-light); }
.ms-btn-danger:hover { background: var(--red); color: #fff; }
.ms-btn-block { width: 100%; padding: 14px; font-size: 15px; }
.ms-btn-sm { padding: 6px 12px; font-size: 12px; }

/* ========== Portal Layout ========== */
.ms-portal { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }

.ms-sidebar {
    background: var(--primary-dark); color: #fff;
    padding: 24px 0;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.ms-sidebar-logo {
    padding: 0 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 16px;
    display: flex; align-items: center; gap: 12px;
}
.ms-sidebar-logo-mark {
    width: 36px; height: 36px;
    background: var(--gold); border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; color: var(--primary-dark);
}
.ms-sidebar-logo-text {
    font-family: 'Playfair Display', serif; font-size: 17px; color: #fff; font-weight: 700;
    line-height: 1;
}
.ms-sidebar-logo-sub {
    font-size: 9px; letter-spacing: 2px; text-transform: uppercase;
    color: rgba(255,255,255,0.5); margin-top: 4px;
}

.ms-sidebar-section {
    padding: 8px 20px; font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1.5px;
    color: rgba(255,255,255,0.4); margin-top: 12px;
}

.ms-sidebar nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 20px; color: rgba(255,255,255,0.7);
    font-size: 14px; transition: all 0.15s;
    border-left: 3px solid transparent;
}
.ms-sidebar nav a:hover {
    color: #fff; background: rgba(255,255,255,0.04);
}
.ms-sidebar nav a.active {
    color: #fff; background: rgba(255,255,255,0.06);
    border-left-color: var(--gold);
}
.ms-sidebar nav a .ms-icon { width: 18px; height: 18px; flex-shrink: 0; }

.ms-sidebar-footer {
    margin-top: auto; padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.08);
}
.ms-sidebar-user {
    display: flex; align-items: center; gap: 10px; padding: 8px;
    border-radius: var(--radius-sm); transition: background 0.15s;
}
.ms-sidebar-user:hover { background: rgba(255,255,255,0.04); }
.ms-sidebar-user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--accent); display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; color: #fff;
}
.ms-sidebar-user-name { font-size: 13px; color: #fff; font-weight: 500; }
.ms-sidebar-user-role { font-size: 11px; color: rgba(255,255,255,0.5); }

.ms-main { padding: 32px; max-width: 1500px; }

.ms-topbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--border);
}
.ms-topbar h1 { font-size: 28px; font-weight: 700; color: var(--text); }
.ms-topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ========== Notifications ========== */
.ms-notice {
    padding: 12px 16px; border-radius: var(--radius);
    margin-bottom: 20px; font-size: 14px;
    border-left: 4px solid;
    display: flex; align-items: center; gap: 10px;
}
.ms-notice-success { background: var(--green-light); color: var(--green); border-color: var(--green); }
.ms-notice-error { background: var(--red-light); color: var(--red); border-color: var(--red); }
.ms-notice-warning { background: var(--orange-light); color: var(--orange); border-color: var(--orange); }
.ms-notice-info { background: var(--blue-light); color: var(--blue); border-color: var(--blue); }

/* ========== KPI Grid ========== */
.ms-kpi-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px; margin-bottom: 28px;
}
.ms-kpi-card {
    background: var(--card); border-radius: var(--radius-lg);
    padding: 20px; box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    transition: transform 0.15s, box-shadow 0.15s;
}
.ms-kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.ms-kpi-card .value { font-size: 30px; font-weight: 800; line-height: 1; }
.ms-kpi-card .label {
    font-size: 11px; color: var(--muted); text-transform: uppercase;
    letter-spacing: 1px; margin-top: 8px;
}
.ms-kpi-card .sub { font-size: 11px; color: var(--muted); margin-top: 4px; }
.ms-kpi-card.green .value { color: var(--green); }
.ms-kpi-card.red .value { color: var(--red); }
.ms-kpi-card.orange .value { color: var(--orange); }
.ms-kpi-card.blue .value { color: var(--blue); }

/* ========== Cards ========== */
.ms-card {
    background: var(--card); border-radius: var(--radius-lg);
    box-shadow: var(--shadow); border: 1px solid var(--border-light);
    margin-bottom: 24px; overflow: hidden;
}
.ms-card-header {
    padding: 16px 20px; border-bottom: 1px solid var(--border-light);
    font-weight: 700; font-size: 15px; color: var(--text);
    display: flex; justify-content: space-between; align-items: center;
}
.ms-card-body { padding: 20px; }

/* ========== Tables ========== */
.ms-table { width: 100%; border-collapse: collapse; }
.ms-table th {
    text-align: left; padding: 12px 20px;
    font-size: 11px; font-weight: 700;
    color: var(--muted); text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.ms-table td {
    padding: 14px 20px; border-bottom: 1px solid var(--border-light);
    font-size: 14px; vertical-align: middle;
}
.ms-table tbody tr { transition: background 0.1s; }
.ms-table tbody tr:hover { background: var(--bg); }
.ms-table tbody tr:last-child td { border-bottom: none; }
.ms-table code {
    font-family: 'JetBrains Mono', monospace; font-size: 11px;
    padding: 2px 8px; background: var(--bg); border-radius: 4px;
    color: var(--muted);
}
.ms-table .ms-actions {
    display: flex; gap: 6px; justify-content: flex-end;
}

.ms-empty {
    padding: 60px 20px; text-align: center; color: var(--muted);
}
.ms-empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.3; }

/* ========== Badges ========== */
.ms-badge {
    display: inline-block; padding: 3px 10px;
    border-radius: 999px; font-size: 11px; font-weight: 600;
    text-transform: capitalize;
}
.ms-badge-active, .ms-badge-paid, .ms-badge-resolved, .ms-badge-completed, .ms-badge-available { background: var(--green-light); color: var(--green); }
.ms-badge-open, .ms-badge-pending, .ms-badge-upcoming, .ms-badge-medium { background: var(--orange-light); color: var(--orange); }
.ms-badge-overdue, .ms-badge-critical, .ms-badge-terminated, .ms-badge-cancelled, .ms-badge-high { background: var(--red-light); color: var(--red); }
.ms-badge-in-progress, .ms-badge-occupied, .ms-badge-long-term { background: var(--blue-light); color: var(--blue); }
.ms-badge-maintenance, .ms-badge-short-term, .ms-badge-low { background: #e5e7eb; color: var(--text-light); }
.ms-badge-inactive, .ms-badge-expired, .ms-badge-revoked { background: #f3f4f6; color: var(--muted); }

/* ========== P&L Bar ========== */
.ms-pl-bar {
    display: flex; gap: 24px; padding: 24px 28px;
    background: linear-gradient(135deg, var(--cream) 0%, #f0ebe2 100%);
    border-radius: var(--radius-lg); margin-bottom: 24px;
    align-items: center; justify-content: center;
    border: 1px solid #e8e2d4;
}
.ms-pl-item { text-align: center; }
.ms-pl-item .val { font-size: 28px; font-weight: 800; line-height: 1; }
.ms-pl-item .lbl {
    font-size: 11px; color: var(--muted); text-transform: uppercase;
    letter-spacing: 1px; margin-top: 6px;
}
.ms-pl-op { font-size: 24px; color: var(--muted); font-weight: 300; }

/* ========== Forms ========== */
.ms-form-card {
    background: var(--card); border-radius: var(--radius-lg);
    box-shadow: var(--shadow); border: 1px solid var(--border-light);
    margin-bottom: 24px; overflow: hidden;
}
.ms-form-card-header {
    padding: 18px 24px; background: var(--cream);
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.ms-form-card-header h2 {
    font-family: 'Playfair Display', serif;
    font-size: 20px; font-weight: 700; color: var(--primary);
}
.ms-form-card-body { padding: 24px; }
.ms-form-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px;
}
.ms-form-group.full { grid-column: 1 / -1; }
.ms-form-actions {
    padding: 16px 24px; background: var(--bg);
    border-top: 1px solid var(--border-light);
    display: flex; justify-content: flex-end; gap: 8px;
}

/* ========== Search & Filters ========== */
.ms-toolbar {
    display: flex; gap: 12px; align-items: center;
    margin-bottom: 20px; flex-wrap: wrap;
}
.ms-search {
    flex: 1; min-width: 200px; max-width: 400px;
    padding: 10px 14px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--card);
    font-size: 14px;
}
.ms-search:focus { outline: none; border-color: var(--primary-light); }
.ms-filter-select {
    padding: 10px 14px; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--card);
    font-size: 14px; cursor: pointer;
}

/* ========== Dialog/Confirm ========== */
.ms-dialog-backdrop {
    position: fixed; inset: 0; background: rgba(15, 36, 25, 0.6);
    backdrop-filter: blur(4px); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.ms-dialog {
    background: var(--card); border-radius: var(--radius-lg);
    max-width: 420px; width: 100%;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.ms-dialog-body { padding: 28px; }
.ms-dialog h3 { font-family: 'Playfair Display', serif; font-size: 22px; margin-bottom: 8px; color: var(--primary); }
.ms-dialog p { color: var(--text-light); font-size: 14px; }
.ms-dialog-actions {
    padding: 14px 20px; background: var(--bg);
    display: flex; justify-content: flex-end; gap: 8px;
    border-top: 1px solid var(--border-light);
}

/* ========== Misc ========== */
.ms-icon { display: inline-block; width: 18px; height: 18px; }
.ms-text-muted { color: var(--muted); }
.ms-text-green { color: var(--green); }
.ms-text-red { color: var(--red); }
.ms-text-bold { font-weight: 700; }
.ms-text-mono { font-family: 'JetBrains Mono', monospace; font-size: 12px; }

/* ID preview (auto-generated next ID, shown read-only on the New form) */
.ms-id-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-soft);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
}
.ms-id-preview code {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 14px;
    font-weight: 600;
    color: var(--forest-dark);
    background: var(--bg);
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid var(--border-light);
}
.ms-id-hint {
    color: var(--muted);
    font-size: 12px;
    font-style: italic;
}

/* ========== Kanban (used on Termine page) ========== */
.ms-kanban {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    padding: 0 0 4px;
}
.ms-kanban-col {
    background: var(--bg-soft);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 10px;
    min-height: 120px;
}
.ms-kanban-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 4px 10px;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
    color: var(--text);
}
.ms-kanban-head strong { font-weight: 600; }
.ms-kanban-count {
    margin-left: auto;
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
}
.ms-kanban-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.ms-kanban-dot-blue   { background: #3b82f6; }
.ms-kanban-dot-green  { background: var(--green); }
.ms-kanban-dot-orange { background: #f59e0b; }
.ms-kanban-dot-purple { background: #8b5cf6; }
.ms-kanban-dot-gray   { background: var(--muted); }
.ms-kanban-body { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; }
.ms-kanban-card {
    display: block;
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 10px 12px;
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s, transform 0.15s;
}
.ms-kanban-card:hover {
    border-color: var(--sage);
    transform: translateY(-1px);
}
.ms-kanban-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 2px;
}
.ms-kanban-name { font-size: 14px; font-weight: 500; color: var(--text); margin-bottom: 2px; }
.ms-kanban-meta { font-size: 12px; color: var(--muted); }
.ms-kanban-empty {
    color: var(--muted);
    text-align: center;
    font-size: 12px;
    padding: 12px 0;
    margin: 0;
}

/* Booking-status badge column on tenants list */
.ms-booking-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}
.ms-booking-pill-on {
    background: rgba(22, 163, 74, 0.12);
    color: var(--green);
}
.ms-booking-pill-warn {
    background: rgba(245, 158, 11, 0.12);
    color: #b45309;
}
.ms-booking-pill-off {
    background: rgba(107, 114, 128, 0.12);
    color: var(--muted);
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
    .ms-portal { grid-template-columns: 1fr; }
    .ms-sidebar { position: relative; height: auto; padding: 16px 0; }
    .ms-sidebar nav { display: flex; overflow-x: auto; padding: 0 8px; }
    .ms-sidebar nav a { white-space: nowrap; padding: 10px 14px; }
    .ms-main { padding: 16px; }
    .ms-kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .ms-form-grid { grid-template-columns: 1fr; }
    .ms-login-page { grid-template-columns: 1fr; }
    .ms-login-brand { display: none; }
    .ms-pl-bar { flex-wrap: wrap; gap: 16px; padding: 20px; }
    .ms-kanban { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .ms-kanban { grid-template-columns: 1fr; }
}
