/* ==========================================================================
   AutomateIT - Portal Styles (Client Portal)
   ========================================================================== */

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

:root {
    --primary: #047857;
    --primary-dark: #065f46;
    --primary-light: #d1fae5;
    --secondary: #0f172a;
    --accent: #10b981;
    --danger: #dc2626;
    --warning: #f59e0b;
    --text: #374151;
    --text-light: #6b7280;
    --bg: #f3f4f6;
    --bg-white: #ffffff;
    --border: #e5e7eb;
    --sidebar-bg: #064e3b;
    --sidebar-text: #a7f3d0;
    --sidebar-hover: #065f46;
    --sidebar-active: #10b981;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.1);
    --transition: 0.2s ease;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* --- Portal Layout --- */
.portal {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: transform var(--transition);
}

.sidebar__header {
    padding: 20px 24px;
    border-bottom: 1px solid #065f46;
}

.sidebar__logo {
    color: white;
    font-size: 22px;
    font-weight: 800;
}

.sidebar__logo:hover { color: white; }

.sidebar__nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--sidebar-text);
    border-radius: var(--radius);
    margin-bottom: 4px;
    font-size: 15px;
    transition: all var(--transition);
}

.sidebar__link:hover {
    background: var(--sidebar-hover);
    color: white;
}

.sidebar__link.active {
    background: var(--sidebar-active);
    color: white;
}

.sidebar__link.active .sidebar__icon {
    opacity: 1;
}

.sidebar__badge {
    background: var(--danger);
    color: white;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: auto;
}

.sidebar__footer {
    padding: 16px 24px;
    border-top: 1px solid #065f46;
}

.sidebar__user {
    display: block;
    color: white;
    font-weight: 600;
    margin-bottom: 2px;
    font-size: 14px;
}

.sidebar__company {
    display: block;
    color: var(--sidebar-text);
    font-size: 12px;
    margin-bottom: 8px;
}

.sidebar__link--logout {
    color: var(--sidebar-text);
    font-size: 13px;
    padding: 4px 0;
}

.sidebar__toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text);
    padding: 4px;
}

/* --- Sidebar Icon --- */
.sidebar__icon {
    width: 20px;
    height: 20px;
    opacity: 0.7;
    flex-shrink: 0;
    transition: opacity var(--transition);
}

.sidebar__link:hover .sidebar__icon {
    opacity: 1;
}

/* --- Sidebar Backdrop (mobile) --- */
.sidebar__backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar__backdrop.active {
    display: block;
    opacity: 1;
}

/* --- Main content --- */
.portal__main {
    flex: 1;
    margin-left: 260px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.portal__header {
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.portal__title {
    font-size: 22px;
    font-weight: 700;
    color: var(--secondary);
}

.portal__content {
    padding: 32px;
    flex: 1;
}

/* --- Portal Footer --- */
.portal__footer {
    border-top: 1px solid var(--border);
    padding: 20px 32px;
    text-align: center;
}

.portal__footer-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    font-size: 13px;
    color: var(--text-light);
}

.portal__footer-content span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* --- Alerts --- */
.alert {
    padding: 14px 20px;
    border-radius: var(--radius);
    margin: 0 32px 16px;
    font-weight: 500;
    font-size: 14px;
}

.alert--success {
    background: #f0fdf4;
    color: #16a34a;
    border: 1px solid #bbf7d0;
}

.alert--error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.alert--warning {
    background: #fffbeb;
    color: #d97706;
    border: 1px solid #fde68a;
}

/* --- Welcome Banner --- */
.welcome-banner {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    color: white;
    padding: 28px 32px;
    border-radius: var(--radius);
    margin-bottom: 28px;
}

.welcome-banner__title {
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 4px;
}

.welcome-banner__subtitle {
    font-size: 15px;
    opacity: 0.85;
}

/* --- Stats cards --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-card__icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-card__icon--projects {
    background: #d1fae5;
    color: #047857;
}

.stat-card__icon--messages {
    background: #dbeafe;
    color: #2563eb;
}

.stat-card__icon--invoices {
    background: #fef3c7;
    color: #d97706;
}

.stat-card__info {
    flex: 1;
}

.stat-card__label {
    font-size: 13px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.stat-card__value {
    font-size: 32px;
    font-weight: 800;
    color: var(--secondary);
}

.stat-card__sub {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 4px;
}

/* --- Tables --- */
.table-wrapper {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}

.table-wrapper--borderless {
    border: none;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    background: var(--bg);
    padding: 12px 16px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover td {
    background: var(--bg);
}

/* --- Badges/Status --- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge--new { background: #dbeafe; color: #2563eb; }
.badge--contacted { background: #fef3c7; color: #d97706; }
.badge--quoted { background: #e0e7ff; color: #4338ca; }
.badge--converted { background: #d1fae5; color: #059669; }
.badge--closed { background: #f3f4f6; color: #6b7280; }

.badge--draft { background: #f3f4f6; color: #6b7280; }
.badge--active { background: #d1fae5; color: #059669; }
.badge--on_hold { background: #fef3c7; color: #d97706; }
.badge--completed { background: #dbeafe; color: #2563eb; }
.badge--cancelled { background: #fef2f2; color: #dc2626; }

.badge--todo { background: #f3f4f6; color: #6b7280; }
.badge--in_progress { background: #dbeafe; color: #2563eb; }
.badge--review { background: #fef3c7; color: #d97706; }
.badge--done { background: #d1fae5; color: #059669; }

.badge--sent { background: #dbeafe; color: #2563eb; }
.badge--paid { background: #d1fae5; color: #059669; }
.badge--overdue { background: #fef2f2; color: #dc2626; }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
    text-decoration: none;
}

.btn--primary { background: var(--primary); color: white; }
.btn--primary:hover { background: var(--primary-dark); color: white; }

.btn--success { background: var(--accent); color: white; }
.btn--success:hover { background: #059669; color: white; }

.btn--danger { background: var(--danger); color: white; }
.btn--danger:hover { background: #b91c1c; color: white; }

.btn--outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn--outline:hover { background: var(--bg); color: var(--text); }

.btn--sm { padding: 5px 12px; font-size: 13px; }

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* --- Forms --- */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-weight: 600;
    color: var(--secondary);
    margin-bottom: 6px;
    font-size: 14px;
}

.form-label--required::after {
    content: ' *';
    color: var(--danger);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg-white);
    transition: border-color var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(4, 120, 87, 0.1);
}

.form-textarea {
    min-height: 120px;
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- Cards --- */
.card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}

.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card__title {
    font-size: 18px;
    font-weight: 700;
    color: var(--secondary);
}

.card__title--mb {
    margin-bottom: 12px;
}

/* --- Project Cards (Dashboard) --- */
.project-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}

.project-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: box-shadow var(--transition), transform var(--transition);
}

.project-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.project-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.project-card__name {
    font-size: 16px;
    font-weight: 700;
    color: var(--secondary);
}

.project-card__meta {
    margin-bottom: 16px;
}

.project-card__deadline {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--text-light);
}

.project-card__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* --- Progress Bar --- */
.progress-bar__wrapper {
    margin-bottom: 16px;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 6px;
}

.progress-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar--lg {
    height: 10px;
    border-radius: 5px;
}

.progress-bar__fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
    border-radius: inherit;
    transition: width 1s ease;
    width: 0%;
}

/* --- Project Progress Card (top of project view) --- */
.project-progress-card {
    margin-bottom: 24px;
}

.project-progress-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.project-progress-card__title {
    font-size: 20px;
    font-weight: 800;
    color: var(--secondary);
}

/* --- Project Layout (two-column) --- */
.project-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

.project-layout__main {
    min-width: 0;
}

.project-layout__sidebar {
    min-width: 0;
}

/* --- Project Description --- */
.project-description {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.project-description__label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--secondary);
}

.project-description__text {
    line-height: 1.8;
    color: var(--text);
}

/* --- Back Link --- */
.back-link {
    margin-bottom: 24px;
    display: inline-flex;
}

/* --- Milestone Timeline --- */
.milestone-timeline {
    position: relative;
    padding-left: 32px;
}

.milestone-timeline::before {
    content: '';
    position: absolute;
    left: 11px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.milestone-timeline__item {
    position: relative;
    padding-bottom: 24px;
}

.milestone-timeline__item:last-child {
    padding-bottom: 0;
}

.milestone-timeline__dot {
    position: absolute;
    left: -32px;
    top: 2px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    color: var(--text-light);
}

.milestone-timeline__item--done .milestone-timeline__dot {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.milestone-timeline__item--in_progress .milestone-timeline__dot {
    background: #dbeafe;
    border-color: #2563eb;
    color: #2563eb;
}

.milestone-timeline__title {
    font-size: 15px;
    font-weight: 600;
    color: var(--secondary);
    margin-bottom: 4px;
}

.milestone-timeline__meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.milestone-timeline__date {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--text-light);
}

/* --- File List / File Item --- */
.file-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

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

.file-item__icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--bg);
    color: var(--text-light);
}

.file-item__icon--pdf {
    background: #fef2f2;
    color: #dc2626;
}

.file-item__icon--spreadsheet {
    background: #d1fae5;
    color: #047857;
}

.file-item__icon--image {
    background: #ede9fe;
    color: #7c3aed;
}

.file-item__icon--archive {
    background: #fef3c7;
    color: #d97706;
}

.file-item__icon--file-text {
    background: #dbeafe;
    color: #2563eb;
}

.file-item__info {
    flex: 1;
    min-width: 0;
}

.file-item__name {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-item__meta {
    display: block;
    font-size: 12px;
    color: var(--text-light);
    margin-top: 2px;
}

/* --- Invoice Summary --- */
.invoice-summary {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 32px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
}

.invoice-summary__icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary-light) 0%, #a7f3d0 100%);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.invoice-summary__info {
    flex: 1;
}

.invoice-summary__label {
    font-size: 13px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.invoice-summary__amount {
    font-size: 28px;
    font-weight: 800;
    color: var(--secondary);
    line-height: 1.2;
}

.invoice-summary__count {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 4px;
}

/* --- Status Dots (invoice timeline) --- */
.status-dots {
    display: inline-flex;
    align-items: center;
    gap: 0;
}

.status-dots__dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
    flex-shrink: 0;
    transition: background var(--transition);
}

.status-dots__dot--active {
    background: var(--accent);
}

.status-dots__line {
    width: 16px;
    height: 2px;
    background: var(--border);
    transition: background var(--transition);
}

.status-dots__line--active {
    background: var(--accent);
}

/* --- Deadline Countdown --- */
.deadline-countdown {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.deadline-countdown--ok {
    color: var(--primary);
}

.deadline-countdown--overdue {
    color: var(--danger);
}

/* --- Quick Links (project sidebar) --- */
.quick-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.quick-links__btn {
    width: 100%;
    justify-content: center;
}

/* --- Message Form --- */
.message-form {
    margin-top: 16px;
}

.message-form .form-group {
    margin-bottom: 12px;
}

.message-form .form-textarea {
    min-height: 80px;
}

/* --- Message Unread --- */
.message--unread {
    border-left: 3px solid var(--accent);
}

.message--unread .message__meta {
    font-weight: 700;
    color: var(--secondary);
}

/* --- Detail view --- */
.detail-grid {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 8px 16px;
}

.detail-grid dt {
    font-weight: 600;
    color: var(--text-light);
    font-size: 14px;
    padding: 4px 0;
}

.detail-grid dd {
    padding: 4px 0;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* --- Actions header --- */
.page-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

/* --- Empty state --- */
.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.empty__icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty__text {
    font-size: 16px;
}

/* --- Text Utilities --- */
.text-muted {
    color: var(--text-light);
}

.text-sm {
    font-size: 14px;
}

/* --- Login page --- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.login-box {
    background: var(--bg-white);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-width: 420px;
    width: 100%;
}

.login-box__title {
    font-size: 24px;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 4px;
}

.login-box__subtitle {
    color: var(--text-light);
    margin-bottom: 24px;
}

/* --- Messages / Chat --- */
.messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
    max-height: 500px;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.6;
}

.message--admin {
    align-self: flex-start;
    background: var(--bg-white);
    border: 1px solid var(--border);
}

.message--client {
    align-self: flex-end;
    background: var(--primary-light);
    border: 1px solid #a7f3d0;
}

.message__meta {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 4px;
}

.message__body {
    word-wrap: break-word;
}

/* --- Notes / Messages (generic) --- */
.note {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.note__header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-light);
}

.note__body {
    font-size: 14px;
    line-height: 1.6;
}

/* --- Drag & Drop Zone --- */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    transition: all 0.2s ease;
    color: var(--text-light);
    font-size: 14px;
    cursor: pointer;
}

.drop-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

.drop-zone__label {
    display: block;
    margin-top: 8px;
    font-weight: 600;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar__toggle {
        display: block;
    }

    .portal__main {
        margin-left: 0;
    }

    .portal__content {
        padding: 16px;
    }

    .portal__header {
        padding: 12px 16px;
    }

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

    .form-row {
        grid-template-columns: 1fr;
    }

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

    .project-layout {
        grid-template-columns: 1fr;
    }

    .project-cards {
        grid-template-columns: 1fr;
    }

    .welcome-banner {
        padding: 20px;
    }

    .welcome-banner__title {
        font-size: 20px;
    }

    .invoice-summary {
        padding: 20px;
    }

    .invoice-summary__amount {
        font-size: 22px;
    }

    .portal__footer-content {
        flex-direction: column;
        gap: 8px;
    }
}
