/* ================================================================
   PresidioCSM – Application Stylesheet
   ================================================================ */

/* ----------------------------------------------------------------
   CSS Custom Properties (design tokens)
   ---------------------------------------------------------------- */
:root {
    --color-brand:       #0070d2;
    --color-brand-dark:  #005bb5;
    --color-brand-light: #e8f4fd;
    --color-success:     #2e7d32;
    --color-success-bg:  #e8f5e9;
    --color-error:       #c62828;
    --color-error-bg:    #ffebee;
    --color-warn:        #e65100;
    --color-warn-bg:     #fff3e0;
    --color-info:        #01579b;
    --color-info-bg:     #e1f5fe;

    --color-text:        #1a1a2e;
    --color-text-muted:  #5f6368;
    --color-border:      #dadce0;
    --color-bg:          #f8f9fa;
    --color-surface:     #ffffff;

    --radius-sm:   4px;
    --radius-md:   8px;
    --radius-lg:   12px;

    --shadow-sm:   0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:   0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);

    --font-sans:   -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-mono:   'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

    --header-h:    60px;
}

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

html { font-size: 16px; }

body {
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--color-brand); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
    font-family: var(--font-mono);
    font-size: .875em;
    background: #f1f3f4;
    padding: 1px 5px;
    border-radius: var(--radius-sm);
}

/* ----------------------------------------------------------------
   Header
   ---------------------------------------------------------------- */
.site-header {
    height: var(--header-h);
    background: var(--color-brand);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: .3px;
}
.brand:hover { text-decoration: none; opacity: .9; }

.header-nav {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    font-size: .9rem;
}

.header-nav a { color: rgba(255,255,255,.9); }
.header-nav a:hover { color: #fff; text-decoration: underline; }

.nav-user {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: rgba(255,255,255,.85);
}

.avatar-sm {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,.4);
}

/* ----------------------------------------------------------------
   Main content
   ---------------------------------------------------------------- */
.main-content {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* ----------------------------------------------------------------
   Footer
   ---------------------------------------------------------------- */
.site-footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 1rem 1.5rem;
    text-align: center;
    color: var(--color-text-muted);
    font-size: .8rem;
}

/* ----------------------------------------------------------------
   Alerts / Flash messages
   ---------------------------------------------------------------- */
.alert {
    padding: .85rem 1.1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.25rem;
    font-size: .9rem;
    border-left: 4px solid transparent;
}

.alert-success { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success); }
.alert-error   { background: var(--color-error-bg);   color: var(--color-error);   border-color: var(--color-error); }
.alert-warn    { background: var(--color-warn-bg);    color: var(--color-warn);    border-color: var(--color-warn); }
.alert-info    { background: var(--color-info-bg);    color: var(--color-info);    border-color: var(--color-info); }

/* ----------------------------------------------------------------
   Buttons
   ---------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .55rem 1.15rem;
    border-radius: var(--radius-md);
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, border-color .15s, opacity .15s;
    text-decoration: none;
    line-height: 1;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
    background: var(--color-brand);
    color: #fff;
    border-color: var(--color-brand);
}
.btn-primary:hover:not(:disabled) {
    background: var(--color-brand-dark);
    border-color: var(--color-brand-dark);
    text-decoration: none;
    color: #fff;
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-brand);
    border-color: var(--color-border);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--color-brand-light);
    text-decoration: none;
}

.btn-danger {
    background: var(--color-surface);
    color: var(--color-error);
    border-color: var(--color-error);
}
.btn-danger:hover:not(:disabled) {
    background: var(--color-error-bg);
    text-decoration: none;
}

.btn-sm { padding: .35rem .75rem; font-size: .82rem; }

.btn-webex {
    font-size: 1rem;
    padding: .75rem 1.75rem;
}

/* ----------------------------------------------------------------
   Badges
   ---------------------------------------------------------------- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    line-height: 1.6;
    text-transform: uppercase;
    letter-spacing: .4px;
}

.badge--group   { background: #e3f2fd; color: #1565c0; }
.badge--direct  { background: #f3e5f5; color: #6a1b9a; }
.badge--success { background: var(--color-success-bg); color: var(--color-success); }
.badge--error   { background: var(--color-error-bg);   color: var(--color-error); }
.badge--warn    { background: var(--color-warn-bg);    color: var(--color-warn); }
.badge--mod     { background: #fff8e1; color: #f57f17; }
.badge--monitor { background: #e8eaf6; color: #283593; }
.badge--me      { background: var(--color-brand-light); color: var(--color-brand); }

.badge-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--color-brand-light);
    color: var(--color-brand);
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    margin-left: .35rem;
}

/* ----------------------------------------------------------------
   Page header
   ---------------------------------------------------------------- */
.page-header {
    margin-bottom: 1.75rem;
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.2;
}

.page-header .subtitle {
    margin-top: .35rem;
    color: var(--color-text-muted);
    font-size: .9rem;
}

.back-link {
    display: inline-block;
    font-size: .85rem;
    color: var(--color-text-muted);
    margin-bottom: .5rem;
}
.back-link:hover { color: var(--color-brand); }

/* ----------------------------------------------------------------
   Login page
   ---------------------------------------------------------------- */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - var(--header-h) - 80px);
}

.login-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2.25rem;
    max-width: 420px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-md);
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: .75rem;
}

.login-desc {
    color: var(--color-text-muted);
    font-size: .9rem;
    margin-bottom: 1.75rem;
    line-height: 1.5;
}

/* ----------------------------------------------------------------
   Space list (index.php)
   ---------------------------------------------------------------- */
.space-list {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.space-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: .9rem 1.1rem;
    text-decoration: none;
    color: var(--color-text);
    transition: box-shadow .15s, border-color .15s;
}

.space-card:hover {
    box-shadow: var(--shadow-sm);
    border-color: var(--color-brand);
    text-decoration: none;
    color: var(--color-text);
}

.space-icon {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.space-icon--group  { background: #e3f2fd; color: #1565c0; }
.space-icon--direct { background: #f3e5f5; color: #6a1b9a; }

.space-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: .2rem;
}

.space-title {
    font-weight: 600;
    font-size: .95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.space-meta {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: .8rem;
    color: var(--color-text-muted);
}

.space-arrow {
    color: var(--color-text-muted);
    font-size: 1.3rem;
    flex-shrink: 0;
}

.results-count {
    margin-top: 1rem;
    font-size: .82rem;
    color: var(--color-text-muted);
}

/* ----------------------------------------------------------------
   Space detail (space.php)
   ---------------------------------------------------------------- */
.space-detail-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 900px) {
    .space-detail-grid {
        grid-template-columns: 1fr;
    }
}

.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.panel-title {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
}

.panel-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: 1rem 1.15rem;
    border-bottom: 1px solid var(--color-border);
    flex-wrap: wrap;
}

.panel-messages .panel-title,
.panel-messages > h2 {
    padding: 1rem 1.15rem;
    border-bottom: 1px solid var(--color-border);
    font-size: 1rem;
    font-weight: 600;
}

/* Messages */
.message-list {
    display: flex;
    flex-direction: column;
}

.message-item {
    padding: .85rem 1.15rem;
    border-bottom: 1px solid var(--color-border);
}
.message-item:last-child { border-bottom: none; }

.message-meta {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: .5rem;
    margin-bottom: .25rem;
}

.message-sender {
    font-weight: 600;
    font-size: .85rem;
    color: var(--color-brand);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}

.message-time {
    font-size: .75rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.message-text {
    font-size: .9rem;
    color: var(--color-text);
    word-break: break-word;
    white-space: pre-wrap;
}

.message-html {
    font-style: italic;
    color: var(--color-text-muted);
}

.message-attachment {
    font-size: .82rem;
    color: var(--color-text-muted);
    margin-top: .25rem;
}

/* People list */
.people-list {
    display: flex;
    flex-direction: column;
}

.person-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .7rem 1.15rem;
    border-bottom: 1px solid var(--color-border);
}
.person-item:last-child { border-bottom: none; }
.person-item--me { background: var(--color-brand-light); }

.person-avatar-placeholder {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--color-brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .9rem;
    text-transform: uppercase;
}

.person-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.person-name {
    font-size: .88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.person-email {
    font-size: .78rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.person-badges {
    display: flex;
    gap: .3rem;
    flex-shrink: 0;
}

.member-badge {
    font-size: .82rem;
    color: var(--color-success);
    font-weight: 500;
}

.add-me-form { flex-shrink: 0; }

.empty-state-sm {
    padding: 1.25rem 1.15rem;
    color: var(--color-text-muted);
    font-size: .875rem;
}

/* ----------------------------------------------------------------
   Settings page
   ---------------------------------------------------------------- */
.settings-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem 1.75rem;
    margin-bottom: 1.5rem;
}

.settings-section h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: .5rem;
}

.settings-desc {
    color: var(--color-text-muted);
    font-size: .875rem;
    margin-bottom: 1.25rem;
    line-height: 1.6;
}

/* Credential card */
.cred-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
}

.cred-row {
    display: flex;
    gap: 1rem;
    padding: .35rem 0;
    border-bottom: 1px solid var(--color-border);
    font-size: .875rem;
    align-items: baseline;
}
.cred-row:last-child { border-bottom: none; }

.cred-label {
    flex: 0 0 120px;
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .4px;
}

.cred-value { flex: 1; word-break: break-word; }

.cred-scopes {
    font-family: var(--font-mono);
    font-size: .78rem;
    color: var(--color-text-muted);
}

/* ----------------------------------------------------------------
   Data table
   ---------------------------------------------------------------- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.data-table th,
.data-table td {
    padding: .6rem .85rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.data-table th {
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--color-text-muted);
    background: var(--color-bg);
    white-space: nowrap;
}

.data-table tbody tr:hover { background: var(--color-bg); }
.data-table tbody tr:last-child td { border-bottom: none; }

.url-cell code { word-break: break-all; font-size: .78rem; }
.id-cell       { font-size: .78rem; color: var(--color-text-muted); }

/* ----------------------------------------------------------------
   Empty state
   ---------------------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--color-text-muted);
    font-size: .9rem;
}

/* ----------------------------------------------------------------
   Add User form (settings page)
   ---------------------------------------------------------------- */
.add-user-form {
    margin-bottom: 0;
}

.add-user-row {
    display: flex;
    gap: .6rem;
    align-items: center;
    flex-wrap: wrap;
}

.form-input {
    flex: 1;
    min-width: 200px;
    padding: .55rem .85rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: .9rem;
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color .15s, box-shadow .15s;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px rgba(0,112,210,.15);
}

.form-input:disabled {
    background: var(--color-bg);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

.form-hint {
    margin-top: .5rem;
    font-size: .8rem;
    color: var(--color-text-muted);
}

/* ----------------------------------------------------------------
   Responsive tweaks
   ---------------------------------------------------------------- */
@media (max-width: 600px) {
    .main-content { padding: 1rem; }

    .space-meta { flex-wrap: wrap; }

    .cred-row { flex-direction: column; gap: .2rem; }
    .cred-label { flex: unset; }

    .data-table { display: block; overflow-x: auto; }

    .settings-section { padding: 1.1rem; }
}
