/* ==========================================================================
   Grey & Associates — Party Wall Project Management System
   ========================================================================== */

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

:root {
    --navy: #1a1a2e;
    --navy-light: #252542;
    --accent: #2c5f8a;
    --accent-hover: #234d72;
    --accent-light: #e8f0f7;
    --white: #ffffff;
    --off-white: #f7f8fa;
    --grey-50: #f9fafb;
    --grey-100: #f3f4f6;
    --grey-200: #e5e7eb;
    --grey-300: #d1d5db;
    --grey-400: #9ca3af;
    --grey-500: #6b7280;
    --grey-600: #4b5563;
    --grey-700: #374151;
    --grey-800: #1f2937;
    --green: #16a34a;
    --green-light: #dcfce7;
    --amber: #d97706;
    --amber-light: #fef3c7;
    --blue: #2563eb;
    --blue-light: #dbeafe;
    --red: #dc2626;
    --red-light: #fee2e2;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 2px 4px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --radius: 8px;
    --radius-sm: 4px;
    --sidebar-width: 240px;
    --header-height: 60px;
    --font-stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body {
    height: 100%;
    font-family: var(--font-stack);
    font-size: 14px;
    line-height: 1.6;
    color: var(--grey-800);
    background: var(--off-white);
}

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

h1, h2, h3, h4, h5, h6 {
    color: var(--navy);
    font-weight: 600;
    line-height: 1.3;
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }

/* ==========================================================================
   Layout — App Shell
   ========================================================================== */

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--navy);
    color: var(--white);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand h1 {
    color: var(--white);
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.sidebar-brand span {
    color: var(--grey-400);
    font-size: 0.7rem;
    display: block;
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1.25rem;
    color: var(--grey-300);
    font-size: 0.9rem;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}
.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255,255,255,0.07);
    color: var(--white);
    text-decoration: none;
}
.sidebar-nav a .nav-icon {
    width: 20px;
    text-align: center;
    font-size: 1rem;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 0.75rem;
    color: var(--grey-500);
}

/* --- Main wrapper --- */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* --- Header --- */
.header {
    height: var(--header-height);
    background: var(--navy);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 90;
}
.header-user {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--grey-300);
    font-size: 0.9rem;
}
.header-user strong {
    color: var(--white);
    font-weight: 500;
}
.header-user a {
    color: var(--grey-400);
    font-size: 0.85rem;
}
.header-user a:hover {
    color: var(--white);
}

.hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--white);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    margin-right: auto;
}

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

/* --- Footer --- */
.app-footer {
    padding: 1.5rem 2rem;
    text-align: center;
    color: var(--grey-400);
    font-size: 0.8rem;
    border-top: 1px solid var(--grey-200);
    background: var(--white);
}

/* ==========================================================================
   Login Page
   ========================================================================== */

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

.login-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}

.login-brand {
    text-align: center;
    margin-bottom: 2rem;
}
.login-brand h1 {
    font-size: 1.5rem;
    color: var(--navy);
    margin-bottom: 0.25rem;
}
.login-brand p {
    color: var(--grey-500);
    font-size: 0.85rem;
}

.login-card .form-group {
    margin-bottom: 1.25rem;
}
.login-card .btn-primary {
    width: 100%;
    padding: 0.65rem;
    font-size: 1rem;
}

.login-error {
    background: var(--red-light);
    color: var(--red);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
}

/* ==========================================================================
   Flash Messages
   ========================================================================== */

.flash {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    transition: opacity 0.4s ease;
    max-width: 600px;
    width: 90%;
    text-align: center;
}
.flash-success {
    background: var(--green);
    color: var(--white);
}
.flash-error {
    background: var(--red);
    color: var(--white);
}
.flash.fade-out {
    opacity: 0;
}

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--grey-200);
}
.card-header h2,
.card-header h3 {
    margin: 0;
}

/* Summary stat cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem 1.5rem;
    text-align: center;
}
.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--navy);
    line-height: 1.2;
}
.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--grey-500);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 0.25rem;
}
.stat-card.stat-current { border-top: 3px solid var(--green); }
.stat-card.stat-quoted { border-top: 3px solid var(--amber); }
.stat-card.stat-invoiced { border-top: 3px solid var(--blue); }
.stat-card.stat-total { border-top: 3px solid var(--accent); }

/* ==========================================================================
   Filter Bar
   ========================================================================== */

.filter-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.filter-bar select,
.filter-bar input[type="search"],
.filter-bar input[type="text"] {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--grey-300);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: var(--font-stack);
    background: var(--white);
}
.filter-bar input[type="search"],
.filter-bar input[type="text"] {
    min-width: 240px;
}
.filter-bar .filter-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--grey-600);
}

/* ==========================================================================
   Tables
   ========================================================================== */

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--white);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
thead th {
    background: var(--grey-50);
    text-align: left;
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: var(--grey-700);
    border-bottom: 2px solid var(--grey-200);
    white-space: nowrap;
}
tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--grey-100);
    vertical-align: middle;
}
tbody tr:hover {
    background: var(--grey-50);
}
tbody tr:nth-child(even) {
    background: var(--grey-50);
}
tbody tr:nth-child(even):hover {
    background: var(--grey-100);
}
tbody tr.clickable-row {
    cursor: pointer;
}

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
    display: inline-block;
    padding: 0.2em 0.7em;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
    line-height: 1.4;
    white-space: nowrap;
}
.badge-current   { background: var(--green-light); color: var(--green); }
.badge-quoted    { background: var(--amber-light); color: var(--amber); }
.badge-invoiced  { background: var(--blue-light);  color: var(--blue); }
.badge-past      { background: var(--grey-200);    color: var(--grey-600); }
.badge-no-go,
.badge-nogo      { background: var(--red-light);   color: var(--red); }

/* Response type badges */
.badge-response  { font-size: 0.7rem; }
.badge-consent   { background: #d1fae5; color: #065f46; }
.badge-dissent   { background: #fecaca; color: #991b1b; }
.badge-d2        { background: #dbeafe; color: #1e40af; }
.badge-noreply   { background: var(--grey-200); color: var(--grey-600); }
.badge-awaiting  { background: var(--amber-light); color: var(--amber); }

/* ==========================================================================
   Progress Bar
   ========================================================================== */

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--grey-200);
    border-radius: 3px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    background: var(--green);
    border-radius: 3px;
    transition: width 0.3s ease;
}
.progress-text {
    font-size: 0.75rem;
    color: var(--grey-500);
    margin-top: 0.2rem;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    font-family: var(--font-stack);
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }

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

.btn-secondary {
    background: var(--grey-200);
    color: var(--grey-700);
}
.btn-secondary:hover {
    background: var(--grey-300);
}

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

.btn-sm {
    padding: 0.3rem 0.9rem;
    font-size: 0.8rem;
}

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

.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ==========================================================================
   Forms
   ========================================================================== */

.form-group {
    margin-bottom: 1.25rem;
}
.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--grey-700);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-control {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--grey-300);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: var(--font-stack);
    color: var(--grey-800);
    background: var(--white);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(44,95,138,0.15);
}

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

select.form-control {
    appearance: auto;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.form-check input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent);
}
.form-check label {
    font-size: 0.9rem;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    margin: 0;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--grey-200);
}

.form-hint {
    font-size: 0.8rem;
    color: var(--grey-500);
    margin-top: 0.2rem;
}

/* --- Fieldset / Legend --- */
fieldset {
    border: 1px solid var(--grey-200);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}
legend {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--navy);
    padding: 0 0.5rem;
}

/* ==========================================================================
   Collapsible Sections
   ========================================================================== */

.collapsible-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.75rem 0;
    user-select: none;
}
.collapsible-header h3 {
    margin: 0;
    font-size: 1rem;
}
.collapsible-header .toggle-arrow {
    transition: transform 0.2s ease;
    font-size: 0.75rem;
    color: var(--grey-500);
}
.collapsible-header .toggle-arrow::before {
    content: "\25B6";
}
.collapsible.expanded .collapsible-header .toggle-arrow::before {
    content: "\25BC";
}
.collapsible-body {
    display: none;
    padding-top: 0.5rem;
}
.collapsible.expanded .collapsible-body {
    display: block;
}

/* ==========================================================================
   Milestones
   ========================================================================== */

.milestone-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.milestone {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--grey-100);
}
.milestone:last-child {
    border-bottom: none;
}
.milestone label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    margin: 0;
}
.milestone input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--green);
    flex-shrink: 0;
}
.milestone.completed span {
    text-decoration: line-through;
    color: var(--grey-400);
}
.milestone-date {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--grey-400);
    font-weight: 400;
}

/* ==========================================================================
   AO Card
   ========================================================================== */

.ao-card {
    background: var(--white);
    border: 1px solid var(--grey-200);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.ao-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}
.ao-card-header h3 {
    margin: 0;
    font-size: 1.05rem;
}
.ao-card-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem 2rem;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}
.ao-card-details dt {
    color: var(--grey-500);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.ao-card-details dd {
    margin: 0 0 0.5rem 0;
    color: var(--grey-800);
}
.ao-card-milestones {
    border-top: 1px solid var(--grey-100);
    padding-top: 0.75rem;
}
.ao-card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--grey-100);
}

/* ==========================================================================
   Project View Header
   ========================================================================== */

.project-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}
.project-header-info h1 {
    margin-bottom: 0.25rem;
}
.project-meta {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--grey-600);
}
.project-meta dt {
    display: inline;
    font-weight: 600;
    color: var(--grey-500);
    font-size: 0.8rem;
    text-transform: uppercase;
}
.project-meta dd {
    display: inline;
    margin: 0 1.5rem 0 0.25rem;
}

/* Address preview */
.address-preview {
    background: var(--grey-50);
    border: 1px solid var(--grey-200);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-family: monospace;
    font-size: 0.85rem;
    white-space: pre-line;
    margin-top: 0.5rem;
}

/* Section headings */
.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 2rem 0 1rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--grey-200);
}
.section-heading h2 {
    margin: 0;
}

/* ==========================================================================
   Breadcrumb
   ========================================================================== */

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--grey-500);
    margin-bottom: 1.5rem;
}
.breadcrumb a {
    color: var(--accent);
}
.breadcrumb .separator::before {
    content: "/";
    margin: 0 0.15rem;
}

/* ==========================================================================
   Notice Details — Dynamic fields
   ========================================================================== */

.detail-field-group {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    margin-bottom: 0.75rem;
}
.detail-field-group .form-group {
    flex: 1;
    margin-bottom: 0;
}
.detail-field-group .btn-remove {
    padding: 0.5rem;
    background: none;
    border: none;
    color: var(--grey-400);
    cursor: pointer;
    font-size: 1.1rem;
}
.detail-field-group .btn-remove:hover {
    color: var(--red);
}

/* Conditional sections */
.conditional-section {
    display: none;
    padding: 1rem;
    background: var(--grey-50);
    border-radius: var(--radius-sm);
    margin-top: 0.75rem;
    margin-bottom: 1rem;
}
.conditional-section.active {
    display: block;
}

/* ==========================================================================
   Response type selector
   ========================================================================== */

.response-selector {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
.response-selector select {
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--grey-300);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: var(--font-stack);
}

/* ==========================================================================
   Utility
   ========================================================================== */

.text-muted { color: var(--grey-500); }
.text-sm    { font-size: 0.85rem; }
.text-xs    { font-size: 0.75rem; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.d-none { display: none; }

.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--grey-500);
}
.empty-state p {
    margin-bottom: 1rem;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }

    .main-wrapper {
        margin-left: 0;
    }

    .hamburger {
        display: block;
    }

    .content {
        padding: 1rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-bar input[type="search"],
    .filter-bar input[type="text"] {
        min-width: 0;
    }

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

    .project-header {
        flex-direction: column;
    }

    .ao-card-details {
        grid-template-columns: 1fr;
    }

    .table-wrapper {
        margin: 0 -1rem;
        border-radius: 0;
    }
}

/* Sidebar overlay on mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
}
.sidebar-overlay.active {
    display: block;
}
