/* Variables for consistency */
:root {
  --primary: #4f46e5;    /* Indigo */
  --success: #10b981;    /* Emerald */
  --danger: #ef4444;     /* Red */
  --dark: #1e293b;       /* Slate */
  --light: #f8fafc;      /* Off-white */
  --border: #e2e8f0;     /* Light Grey */
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --radius: 8px;
  --control-height: 44px;
  --page-padding: 1.25rem;
  --content-width: 960px;
}

/* Global layout */
body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 
    max-width: var(--content-width); /* Slightly wider for better breathing room */
    margin: 2.5rem auto; 
    padding: 0 var(--page-padding);
    background-color: var(--light);
    color: #334155;
    line-height: 1.6;
}

.container {
    width: 100%;
    max-width: var(--content-width);
    margin: 0 auto;
}

/* Navbar */
.navbar { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    background: white; /* Clean white look */
    padding: 1rem 1.5rem; 
    border-radius: var(--radius); 
    margin-bottom: 30px; 
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.navbar a { 
    color: #475569; 
    text-decoration: none; 
    margin-right: 20px; 
    font-weight: 500;
    transition: color 0.2s;
}

.navbar a:hover {
    color: var(--primary);
}

.link-logout { 
    color: var(--danger) !important; 
    font-weight: 600;
}
.link-logout:hover { text-decoration: underline; }

.link-login { 
    color: var(--primary) !important; 
    font-weight: 600; 
}

/* Tables */
.styled-table { 
    width: 100%; 
    border-collapse: separate; /* Allows border radius on rows */
    border-spacing: 0;
    margin-top: 20px; 
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.styled-table th, .styled-table td { 
    padding: 16px; 
    text-align: left; 
    border-bottom: 1px solid var(--border);
}

.styled-table th { 
    background-color: #f1f5f9; 
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    border-top: none;
}

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

.table-actions { 
    display: flex; 
    gap: 8px; 
    align-items: center; 
}

/* Forms */
.form-container { 
    max-width: 450px; 
    margin: 0 auto; 
    background: white;
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.form-row { margin-bottom: 20px; }
.form-inline { margin: 0; }

.input-full { 
    width: 100%; 
    box-sizing: border-box; 
    padding: 0 12px; 
    height: var(--control-height);
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.input-full:focus, input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Global Input Style Upgrade */
input { 
    height: var(--control-height);
    padding: 0 12px; 
    margin-right: 5px; 
    border: 1px solid #cbd5e1; 
    border-radius: 6px; 
    font-family: inherit;
    box-sizing: border-box;
}

/* Buttons */
/* Buttons */
.btn { 
    display: inline-flex;          /* Use flex to center text perfectly */
    justify-content: center;       /* Center text horizontally */
    align-items: center;           /* Center text vertically */
    min-width: 110px;              /* FORCE EQUAL WIDTH: All buttons are at least this wide */
    min-height: var(--control-height); /* Ensure consistent height */
    padding: 0 16px;            /* Increased padding for better click area */
    border: none; 
    cursor: pointer; 
    border-radius: 6px; 
    color: white; 
    font-weight: 500;
    font-size: 0.9rem;             /* Standardized font size for ALL buttons */
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    box-sizing: border-box;
    vertical-align: middle;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    font-family: inherit;
}

.btn:hover { 
    transform: translateY(-1px); 
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); 
}

/* Button Colors */
.btn-add { background-color: var(--success); }
.btn-add:hover { background-color: #059669; }

.btn-update { background-color: var(--primary); }
.btn-update:hover { background-color: #4338ca; }

.btn-delete { 
    background-color: var(--danger); 
    /* Removed font-size override so it matches others exactly */
}
.btn-delete:hover { background-color: #dc2626; }

/* Link looking like a button */
.btn-link { 
    display: inline-flex;          /* Match the .btn flex behavior */
    justify-content: center;
    align-items: center;
    min-width: 110px;              /* Match the .btn width */
    min-height: var(--control-height);
    padding: 0 16px; 
    background: var(--primary); 
    color: white; 
    text-decoration: none; 
    border-radius: 6px; 
    font-size: 0.9rem; 
    transition: background 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.btn-link:hover { background-color: #4338ca; }

/* Full width button override */
.btn-full { 
    width: 100%;                   /* Overrides min-width for full width forms */
    display: flex;                 /* Ensures flex behavior applies */
    justify-content: center;
    align-items: center;
    padding: 0 16px; 
    height: var(--control-height);
    border: none; 
    border-radius: 6px; 
    background: var(--primary); 
    color: white; 
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-full:hover { background-color: #4338ca; }

.btn-cancel { 
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--control-height);
    min-width: 110px;
    margin-left: 10px; 
    text-decoration: none; 
    color: #475569; 
    font-weight: 500;
    padding: 0 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
}
.btn-cancel:hover { color: #334155; background: #f8fafc; text-decoration: none; }

/* Alerts */
.alert { 
    padding: 16px; 
    background: #ecfdf5; 
    color: #065f46; 
    margin-bottom: 20px; 
    border: 1px solid #a7f3d0; 
    border-radius: var(--radius); 
    font-weight: 500;
}

.alert--error { 
    background: #fef2f2; 
    color: #991b1b; 
    border-color: #fecaca; 
}

/* Footer */
footer { 
    margin-top: 60px; 
    text-align: center; 
    color: #94a3b8; 
    font-size: 0.9rem;
}

/* Layout helpers for the main CRUD form */
.container > form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.container > form input { }

@media (min-width: 721px) {
    .container > form input {
        flex: 1 1 220px;
    }
}

.container > form .btn,
.container > form .btn-cancel {
    flex: 0 0 auto;
}

.table-actions .btn,
.table-actions .btn-link {
    min-width: 110px;
    min-height: var(--control-height);
}

@media (max-width: 900px) {
    body {
        margin: 2rem auto;
    }

    .navbar {
        flex-wrap: wrap;
        gap: 8px;
    }
}

@media (max-width: 720px) {
    :root {
        --control-height: 40px;
    }

    body {
        margin: 1.5rem auto;
        padding: 0 1rem;
    }

    .navbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .navbar a {
        margin-right: 0;
    }

    .container > form {
        flex-direction: column;
        align-items: stretch;
    }

    .container > form input,
    .container > form .btn,
    .container > form .btn-cancel {
        width: 100%;
    }

    .styled-table {
        display: block;
        width: 100%;
        overflow-x: auto;
    }

    .table-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .table-actions .btn,
    .table-actions .btn-link {
        width: 100%;
        min-width: 0;
    }
}

.visually-hidden {
    display: none;
    visibility: hidden;
}