/* Apex Web Forge — Client Portal Styles
   Matches main site aesthetic: warm cream, forest green, orange-red accent */
@import url('https://fonts.googleapis.com/css2?family=Cabinet+Grotesk:wght@400;500;700;800;900&family=Instrument+Serif:ital@0;1&family=DM+Sans:wght@300;400;500;600&display=swap');

:root {
    --ink: #0a0a0a;
    --paper: #f5f0eb;
    --cream: #efe8e0;
    --accent: #e8431e;
    --accent-glow: #ff5a35;
    --accent-dark: #c4350f;
    --forest: #1a3a2a;
    --sage: #6b8f71;
    --muted: #7a756f;
    --light-muted: #b0aaa3;
    --divider: rgba(10,10,10,0.08);
    --card: #ffffff;
    --card-hover: #fafaf8;
    --input-bg: #ffffff;
    --input-border: rgba(10,10,10,0.12);
    --input-focus: #e8431e;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
    --shadow-md: 0 8px 30px rgba(0,0,0,0.06);
    --shadow-lg: 0 20px 60px rgba(0,0,0,0.08);
    --success: #2d8a4e;
    --success-bg: rgba(45,138,78,0.08);
    --error: #c4350f;
    --error-bg: rgba(196,53,15,0.06);
    --warning: #b8860b;
    --radius: 16px;
    --radius-sm: 10px;
    --transition: 0.2s ease;

    /* Backward-compatible aliases for portal pages */
    --bg-primary: var(--paper);
    --bg-card: var(--card);
    --bg-input: var(--input-bg);
    --bg-hover: var(--card-hover);
    --border: var(--input-border);
    --border-focus: var(--input-focus);
    --text-primary: var(--ink);
    --text-secondary: var(--muted);
    --text-muted: var(--light-muted);
    --accent-hover: var(--accent-dark);
    --accent-glow: rgba(232,67,30,0.1);
    --radius-lg: var(--radius);
}

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

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--paper);
    color: var(--ink);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Grain overlay */
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 9999;
}

/* ---- Auth Layout (login, register, forgot, reset, verify) ---- */
.auth-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
    position: relative;
}

.auth-card {
    width: 100%;
    max-width: 440px;
    background: var(--card);
    border: 1px solid var(--divider);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-md);
    position: relative;
    z-index: 1;
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo a {
    font-family: 'Cabinet Grotesk', sans-serif;
    font-weight: 900;
    font-size: 1.4rem;
    color: var(--ink);
    text-decoration: none;
    letter-spacing: -0.03em;
}

.auth-logo a span {
    color: var(--accent);
}

.auth-logo p {
    color: var(--muted);
    font-size: 0.88rem;
    margin-top: 0.4rem;
}

.auth-card h1 {
    font-family: 'Cabinet Grotesk', sans-serif;
    font-weight: 800;
    font-size: 1.6rem;
    margin-bottom: 0.4rem;
    letter-spacing: -0.03em;
    color: var(--ink);
}

.auth-card .subtitle {
    color: var(--muted);
    font-size: 0.95rem;
    margin-bottom: 1.75rem;
    line-height: 1.5;
}

/* ---- Forms ---- */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ink);
    margin-bottom: 0.4rem;
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-sm);
    color: var(--ink);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.95rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-group input::placeholder {
    color: var(--light-muted);
}

.form-group input:focus {
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px rgba(232,67,30,0.1);
}

.form-group input.error {
    border-color: var(--error);
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row .form-group {
    flex: 1;
}

.password-wrapper {
    position: relative;
}

.password-toggle {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--light-muted);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.25rem;
    transition: color var(--transition);
}

.password-toggle:hover {
    color: var(--muted);
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.85rem 1.75rem;
    border: none;
    border-radius: 100px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    outline: none;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(232,67,30,0.2);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: var(--card);
    color: var(--ink);
    border: 1px solid var(--input-border);
}

.btn-secondary:hover {
    background: var(--card-hover);
    border-color: var(--light-muted);
}

.btn .spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---- Links ---- */
.auth-links {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 0.9rem;
    color: var(--muted);
}

.auth-links a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    transition: color var(--transition);
}

.auth-links a:hover {
    color: var(--accent-dark);
}

.form-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    font-size: 0.85rem;
}

.form-footer a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition);
}

.form-footer a:hover {
    color: var(--accent-dark);
}

/* ---- Alerts ---- */
.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
    display: none;
    line-height: 1.5;
}

.alert.show {
    display: block;
}

.alert-error {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid rgba(196,53,15,0.12);
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(45,138,78,0.12);
}

/* ---- Dashboard Layout ---- */
.portal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background: var(--card);
    border-bottom: 1px solid var(--divider);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.portal-header .logo a {
    font-family: 'Cabinet Grotesk', sans-serif;
    font-weight: 900;
    font-size: 1.2rem;
    color: var(--ink);
    text-decoration: none;
    letter-spacing: -0.03em;
}

.portal-header .logo a span {
    color: var(--accent);
}

.portal-header .user-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.portal-header .user-name {
    font-size: 0.9rem;
    color: var(--muted);
}

.portal-header .btn-logout {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--input-border);
    border-radius: 100px;
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    transition: all var(--transition);
}

.portal-header .btn-logout:hover {
    color: var(--ink);
    border-color: var(--light-muted);
}

.portal-body {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
}

.portal-body h2 {
    font-family: 'Cabinet Grotesk', sans-serif;
    font-weight: 800;
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    letter-spacing: -0.03em;
}

/* ---- Dashboard Cards ---- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.dash-card {
    background: var(--card);
    border: 1px solid var(--divider);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition);
}

.dash-card:hover {
    box-shadow: var(--shadow-md);
}

.dash-card h3 {
    font-family: 'Cabinet Grotesk', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dash-card .card-icon {
    font-size: 1.1rem;
}

.dash-card p {
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

/* ---- Projects ---- */
.project-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
    border-bottom: 1px solid var(--divider);
}

.project-item:last-child {
    border-bottom: none;
}

.project-name {
    font-weight: 500;
}

.project-status {
    font-size: 0.8rem;
    padding: 0.3rem 0.75rem;
    border-radius: 100px;
    font-weight: 600;
}

.status-discovery {
    background: rgba(184,134,11,0.08);
    color: var(--warning);
}

.status-proposal {
    background: rgba(107,143,113,0.1);
    color: var(--sage);
}

.status-in-progress {
    background: rgba(232,67,30,0.08);
    color: var(--accent);
}

.status-review {
    background: rgba(107,143,113,0.1);
    color: var(--sage);
}

.status-completed {
    background: var(--success-bg);
    color: var(--success);
}

.status-on-hold {
    background: rgba(122,117,111,0.08);
    color: var(--muted);
}

/* ---- Tickets ---- */
.ticket-list {
    list-style: none;
}

.ticket-item {
    padding: 1rem;
    border: 1px solid var(--divider);
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    cursor: pointer;
    background: var(--card);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.ticket-item:hover {
    border-color: var(--light-muted);
    box-shadow: var(--shadow-sm);
}

.ticket-subject {
    font-weight: 500;
    margin-bottom: 0.35rem;
}

.ticket-meta {
    font-size: 0.8rem;
    color: var(--light-muted);
    display: flex;
    gap: 1rem;
}

.ticket-status {
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    font-weight: 600;
}

.status-open {
    background: rgba(232,67,30,0.08);
    color: var(--accent);
}

.status-closed {
    background: rgba(122,117,111,0.08);
    color: var(--muted);
}

/* ---- New Ticket Form ---- */
.ticket-form {
    background: var(--card);
    border: 1px solid var(--divider);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.ticket-form textarea {
    width: 100%;
    min-height: 120px;
    padding: 0.75rem 1rem;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-sm);
    color: var(--ink);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.95rem;
    resize: vertical;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.ticket-form textarea:focus {
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px rgba(232,67,30,0.1);
}

/* ---- Tabs ---- */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--divider);
    margin-bottom: 1.5rem;
}

.tab {
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--light-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: 'DM Sans', sans-serif;
}

.tab:hover {
    color: var(--muted);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--light-muted);
}

.empty-state .icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.empty-state p {
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}

/* ---- Reply Badge (client unread) ---- */
.reply-badge {
    font-size: 0.7rem;
    background: var(--accent);
    color: #fff;
    padding: 0.15rem 0.5rem;
    border-radius: 100px;
    font-weight: 700;
    margin-left: 0.5rem;
}

/* ---- Reply Bubbles ---- */
.reply-bubble {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    line-height: 1.65;
}

.reply-admin {
    background: rgba(26,58,42,0.06);
    border-left: 3px solid var(--forest);
}

.reply-client {
    background: var(--card-hover);
    border-left: 3px solid var(--divider);
}

.reply-author {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: var(--muted);
}

.reply-time {
    font-size: 0.7rem;
    color: var(--light-muted);
    margin-top: 0.3rem;
}

/* ---- Ticket Detail ---- */
.ticket-detail-panel {
    background: var(--card);
    border: 1px solid var(--divider);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.btn-back {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    border-radius: 100px;
    border: 1px solid var(--input-border);
    background: var(--card);
    color: var(--ink);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    transition: all 0.2s;
    margin-bottom: 1rem;
}

.btn-back:hover {
    border-color: var(--light-muted);
    background: var(--card-hover);
}

/* ---- Admin Link ---- */
.admin-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.85rem;
    margin-right: 0.75rem;
    font-weight: 600;
    transition: color 0.2s;
}

.admin-link:hover {
    color: var(--accent-dark);
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
    .auth-card {
        padding: 2rem 1.5rem;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .portal-header {
        padding: 1rem;
    }

    .portal-body {
        padding: 1.25rem;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}
